Skip to content

fix: guard require.extensions for Node 24.15+ under Yarn PnP#93248

Draft
bmorros94 wants to merge 1 commit intovercel:canaryfrom
bmorros94:fix/node24-require-extensions
Draft

fix: guard require.extensions for Node 24.15+ under Yarn PnP#93248
bmorros94 wants to merge 1 commit intovercel:canaryfrom
bmorros94:fix/node24-require-extensions

Conversation

@bmorros94
Copy link
Copy Markdown

Summary

  • Guard all require.extensions accesses in packages/next/src/build/next-config-ts/require-hook.ts against undefined
  • On Node 24.15+, the require function passed to CJS modules loaded via the ESM loader no longer has .extensions when the module source comes through a custom loader (Yarn PnP's zip loader), causing next build to crash with a TypeError at module load time
  • Uses 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 #92935

Test plan

  • Verify next build works on Node 24.15+ with Yarn PnP (the crash scenario from the issue)
  • Verify next build still works on Node 20/22 with Yarn PnP (no regression)
  • Verify next build works with next.config.ts projects (the require-hook code path)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next build crashes on Node 24.15+ and 25.7+ under Yarn PnP: require.extensions undefined in next-config-ts/require-hook.js

1 participant