fix(aws): copy server/instrumentation.js into standalone dir on Next.js 16#1195
Open
JiahaoZhu11 wants to merge 1 commit into
Open
fix(aws): copy server/instrumentation.js into standalone dir on Next.js 16#1195JiahaoZhu11 wants to merge 1 commit into
JiahaoZhu11 wants to merge 1 commit into
Conversation
Next.js 16's standalone output no longer includes server/instrumentation.js in the standalone directory. copyTracedFiles copies the instrumentation .nft.json trace and then asserts the .js exists in standaloneNextDir, throwing "File server/instrumentation.js does not exist" during the server bundle. Copy the instrumentation .js from the build dir into the standalone dir (mirroring the existing .nft.json copy) so the assertion passes and the file ships in the bundle.
🦋 Changeset detectedLatest commit: 2629b67 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.
Problem
On Next.js 16,
open-next buildfails during the server-function bundle:Root cause
Next 16's
output: "standalone"no longer copiesserver/instrumentation.jsinto the standalone output dir (it remains only in.next/server/). IncopyTracedFiles, the instrumentation block copies the instrumentation.nft.jsontrace intostandaloneNextDirand then callscomputeCopyFilesForPage("instrumentation"), which asserts thatserver/instrumentation.jsexists instandaloneNextDir— so it throws. (Middleware is unaffected because its.jsis emitted into the standalone dir.)Fix
Before the assertion, copy
server/instrumentation.jsfrom the build dir into the standalone dir — mirroring the existing.nft.jsoncopy right above it — guarded so it only runs when the file exists in the build dir and isn't already present in the standalone dir. Pre-16 behavior is unchanged, and the instrumentation file ships in the bundle.Validation
Reproduced on a real pnpm monorepo app: Next.js 16.1.6, App Router,
next-intlmiddleware,@opennextjs/aws@4.0.3, monorepo config (packageJsonPath/appPath/buildOutputPath) +output: "standalone"+outputFileTracingRoot.copyTracedFileswith the error above.open-next buildcompletes; the full bundle is produced (server-functions/default,assets,cache,dynamodb-provider,revalidation-function,image-optimization-function,warmer-function); the server-function bundle loads and exportshandler;server/instrumentation.jsis present in the server-function output.A patch changeset is included.
🤖 Generated with Claude Code