Skip to content

Commit

Permalink
Fix instrumentation.js initialization in prod on Vercel (#48557)
Browse files Browse the repository at this point in the history
If `this.serverOptions.dir` is `'.'` or missing (which seems to be the
case in Vercel's `___next_launcher.cjs`), this code was calling
`require(join('.', '.next', 'server', 'instrumentation'))` which is
`require('.next/server/instrumentation')`; notably, require treats this
differently from `require('./.next/server/instrumentation')`, which is
actually what we need here.

Use `path.resolve` instead so that we pass an absolute path to
`require`, which I confirmed fixes the issue.
  • Loading branch information
sophiebits authored Apr 19, 2023
1 parent 7350c5f commit 56b32eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export default class NextNodeServer extends BaseServer {
this.nextConfig.experimental.instrumentationHook
) {
try {
const instrumentationHook = await require(join(
const instrumentationHook = await require(resolve(
this.serverOptions.dir || '.',
this.serverOptions.conf.distDir!,
'server',
Expand Down

0 comments on commit 56b32eb

Please sign in to comment.