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.
This commit is contained in:
Sophie Alpert 2023-04-19 01:00:29 -07:00 committed by GitHub
parent 7350c5fb34
commit 56b32eb5ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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',