Skip to content

Commit 5fbc23e

Browse files
authoredOct 2, 2023
misc: fix instrumentation with bundled server (#56318)
This PR fixes an issue with the instrumentation hook breaking with the bundled server. I'll follow up with a better test setup for the bundled server in a follow up (tomorrow). <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
1 parent 98432a4 commit 5fbc23e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed
 

‎packages/next/src/server/next-server.ts

+20-9
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ import { loadManifest } from './load-manifest'
101101

102102
export * from './base-server'
103103

104+
declare const __non_webpack_require__: NodeRequire
105+
106+
const dynamicRequire = process.env.NEXT_MINIMAL
107+
? __non_webpack_require__
108+
: require
109+
104110
function writeStdoutLine(text: string) {
105111
process.stdout.write(' ' + text + '\n')
106112
}
@@ -244,12 +250,15 @@ export default class NextNodeServer extends BaseServer {
244250
this.nextConfig.experimental.instrumentationHook
245251
) {
246252
try {
247-
const instrumentationHook = await require(resolve(
248-
this.serverOptions.dir || '.',
249-
this.serverOptions.conf.distDir!,
250-
'server',
251-
INSTRUMENTATION_HOOK_FILENAME
252-
))
253+
const instrumentationHook = await dynamicRequire(
254+
resolve(
255+
this.serverOptions.dir || '.',
256+
this.serverOptions.conf.distDir!,
257+
'server',
258+
INSTRUMENTATION_HOOK_FILENAME
259+
)
260+
)
261+
253262
await instrumentationHook.register?.()
254263
} catch (err: any) {
255264
if (err.code !== 'MODULE_NOT_FOUND') {
@@ -289,9 +298,11 @@ export default class NextNodeServer extends BaseServer {
289298
const { incrementalCacheHandlerPath } = this.nextConfig.experimental
290299

291300
if (incrementalCacheHandlerPath) {
292-
CacheHandler = require(isAbsolute(incrementalCacheHandlerPath)
293-
? incrementalCacheHandlerPath
294-
: join(this.distDir, incrementalCacheHandlerPath))
301+
CacheHandler = dynamicRequire(
302+
isAbsolute(incrementalCacheHandlerPath)
303+
? incrementalCacheHandlerPath
304+
: join(this.distDir, incrementalCacheHandlerPath)
305+
)
295306
CacheHandler = CacheHandler.default || CacheHandler
296307
}
297308

0 commit comments

Comments
 (0)
Please sign in to comment.