fix: guard require.extensions for Node 24.15+ under Yarn PnP#93248
Draft
bmorros94 wants to merge 1 commit intovercel:canaryfrom
Draft
fix: guard require.extensions for Node 24.15+ under Yarn PnP#93248bmorros94 wants to merge 1 commit intovercel:canaryfrom
bmorros94 wants to merge 1 commit intovercel:canaryfrom
Conversation
On Node 24.15+, the `require` function passed to CJS modules loaded via the ESM loader no longer has `.extensions` defined when the module source comes through a custom loader (Yarn PnP's zip loader). This causes `next build` to crash with a TypeError at module load time. Add optional chaining on the top-level read and early-return guards in registerHook/deregisterHook so the file loads safely when require.extensions is undefined. No behavior change on Node versions where require.extensions is defined. Fixes vercel#92935
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
require.extensionsaccesses inpackages/next/src/build/next-config-ts/require-hook.tsagainstundefinedrequirefunction passed to CJS modules loaded via the ESM loader no longer has.extensionswhen the module source comes through a custom loader (Yarn PnP's zip loader), causingnext buildto crash with aTypeErrorat module load time?.) on the top-level read and early-return guards inregisterHook/deregisterHookso the file loads safely whenrequire.extensionsis undefinedrequire.extensionsis definedFixes #92935
Test plan
next buildworks on Node 24.15+ with Yarn PnP (the crash scenario from the issue)next buildstill works on Node 20/22 with Yarn PnP (no regression)next buildworks withnext.config.tsprojects (therequire-hookcode path)