From 56b32eb5ee0135b4d0517bf5555dc9c0823f9240 Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Wed, 19 Apr 2023 01:00:29 -0700 Subject: [PATCH] Fix instrumentation.js initialization in prod on Vercel (#48557) 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. --- packages/next/src/server/next-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/server/next-server.ts b/packages/next/src/server/next-server.ts index 47f7ec2aa5087..de4ba9e6eb295 100644 --- a/packages/next/src/server/next-server.ts +++ b/packages/next/src/server/next-server.ts @@ -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',