Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/next16-standalone-instrumentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@opennextjs/aws": patch
---

Fix `server/instrumentation.js does not exist` build failure on Next.js 16

On Next.js 16 the standalone output no longer copies `server/instrumentation.js`
into the standalone directory, but `copyTracedFiles` copies the instrumentation
`.nft.json` trace and then asserts the `.js` file exists in the standalone dir,
throwing `File server/instrumentation.js does not exist` during the server
bundle. The instrumentation file is now copied 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.
14 changes: 14 additions & 0 deletions packages/open-next/src/build/copyTracedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ File ${serverPath} does not exist
path.join(dotNextDir, INSTRUMENTATION_TRACE_FILE),
path.join(standaloneNextDir, INSTRUMENTATION_TRACE_FILE),
);
// Next 16's standalone output no longer includes `server/instrumentation.js`
// in the standalone dir, but `computeCopyFilesForPage` asserts it exists
// there. Copy it from the build dir (mirroring the .nft.json copy above) so
// the assertion passes and the instrumentation file ships in the bundle.
const instrumentationServerFile = path.join("server", "instrumentation.js");
if (
existsSync(path.join(dotNextDir, instrumentationServerFile)) &&
!existsSync(path.join(standaloneNextDir, instrumentationServerFile))
) {
copyFileAndMakeOwnerWritable(
path.join(dotNextDir, instrumentationServerFile),
path.join(standaloneNextDir, instrumentationServerFile),
);
}
computeCopyFilesForPage("instrumentation");
logger.debug("Adding instrumentation trace files");
}
Expand Down