Skip to content

fix: getBundlerRuntime should respect buildOutputPath - #1208

Open
yuanzhixiang wants to merge 1 commit into
opennextjs:mainfrom
yuanzhixiang:fix/bundler-runtime-respects-build-output-path
Open

fix: getBundlerRuntime should respect buildOutputPath#1208
yuanzhixiang wants to merge 1 commit into
opennextjs:mainfrom
yuanzhixiang:fix/bundler-runtime-respects-build-output-path

Conversation

@yuanzhixiang

@yuanzhixiang yuanzhixiang commented Aug 6, 2026

Copy link
Copy Markdown

What

getBundlerRuntime resolves the Next.js server output from options.appPath:

https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/helper.ts#L514

appPath is always the project root (process.cwd() + config.appPath) and does not follow the buildOutputPath config. Every other consumer of the Next.js build output resolves it from appBuildOutputPathgetBuildId (helper.ts#L277), copyEnvFile, createServerBundle, createAssets, generateOutput, and the Cloudflare adapter's bundle-server.

This changes that one call site to use appBuildOutputPath.

Why

With buildOutputPath set to anything other than ., the build fails at the bundling stage:

Building server function: default...
Error: Unable to determine Next.js runtime (webpack or turbopack)
    at Module.getBundlerRuntime (.../build/helper.js:385:11)
    at Module.getEnvVarsPatch (.../build/patch/patches/patchEnvVar.js:23:37)
    at generateBundle (.../cli/build/open-next/createServerBundle.js:140:20)

The Next.js build itself succeeds and lands in <buildOutputPath>/.next, but getBundlerRuntime looks for <projectRoot>/.next/server and finds nothing.

This is easy to miss because a stale .next left in the project root from an earlier build satisfies the check — the failure only surfaces on a clean tree, or after the leftover directory is removed.

Reproduced with @opennextjs/cloudflare 1.20.2 / @opennextjs/aws 4.1.0 / Next.js 16.3.0 (Turbopack), on a monorepo app that sets buildOutputPath: ".cache" to keep build artifacts out of the project root. With the fix applied, the same build completes and emits the worker under the configured output path.

Related

@opennextjs/cloudflare has the same class of bug in retrieveCompiledConfig, which breaks deploy (and preview/upload/populateCache) under a custom buildOutputPath. Fixed in opennextjs/opennextjs-cloudflare#1332. Both are needed for buildOutputPath to work end to end — with only this one applied the build succeeds and the deploy then fails on the compiled config lookup.

Testing

biome ci and pnpm test pass locally.

getBundlerRuntime resolved the Next.js server output from appPath, which is
always the project root and does not follow the buildOutputPath config. Every
other consumer of the Next.js build output resolves it from appBuildOutputPath.

Setting buildOutputPath to anything but "." therefore failed the build with
"Unable to determine Next.js runtime (webpack or turbopack)" as soon as the
project root no longer contained a stale .next directory.
@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e9562d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant