fix: getBundlerRuntime should respect buildOutputPath - #1208
Open
yuanzhixiang wants to merge 1 commit into
Open
Conversation
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 detectedLatest commit: 4e9562d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
getBundlerRuntimeresolves the Next.js server output fromoptions.appPath:https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/build/helper.ts#L514
appPathis always the project root (process.cwd()+config.appPath) and does not follow thebuildOutputPathconfig. Every other consumer of the Next.js build output resolves it fromappBuildOutputPath—getBuildId(helper.ts#L277),copyEnvFile,createServerBundle,createAssets,generateOutput, and the Cloudflare adapter'sbundle-server.This changes that one call site to use
appBuildOutputPath.Why
With
buildOutputPathset to anything other than., the build fails at the bundling stage:The Next.js build itself succeeds and lands in
<buildOutputPath>/.next, butgetBundlerRuntimelooks for<projectRoot>/.next/serverand finds nothing.This is easy to miss because a stale
.nextleft 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/cloudflare1.20.2 /@opennextjs/aws4.1.0 / Next.js 16.3.0 (Turbopack), on a monorepo app that setsbuildOutputPath: ".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/cloudflarehas the same class of bug inretrieveCompiledConfig, which breaks deploy (andpreview/upload/populateCache) under a custombuildOutputPath. Fixed in opennextjs/opennextjs-cloudflare#1332. Both are needed forbuildOutputPathto work end to end — with only this one applied the build succeeds and the deploy then fails on the compiled config lookup.Testing
biome ciandpnpm testpass locally.