Skip to content

fix(require-hook): guard require.extensions accesses for Node 24.15+ Yarn PnP#92967

Open
sleitor wants to merge 1 commit intovercel:canaryfrom
sleitor:fix-92935
Open

fix(require-hook): guard require.extensions accesses for Node 24.15+ Yarn PnP#92967
sleitor wants to merge 1 commit intovercel:canaryfrom
sleitor:fix-92935

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Apr 18, 2026

What?

Guard all require.extensions accesses in packages/next/src/build/next-config-ts/require-hook.ts with optional chaining / early-return guards.

Why?

Node.js v24.15.0 introduced a regression (nodejs/node#61769) where the require function exposed to CJS modules loaded via the ESM loader no longer carries the .extensions property when the module source comes through a custom loader (e.g. Yarn PnP zip loader).

This causes a crash at module evaluation time — before registerHook is even called — making every Yarn PnP user on Node 24.15+ unable to run next build:

TypeError: Cannot read properties of undefined (reading '.js')
    at Object.<anonymous> (.../next/dist/build/next-config-ts/require-hook.js:35:37)

The crash happens regardless of whether the project uses next.config.ts or next.config.mjs because transpile-config.js imports require-hook.js eagerly at top level.

How?

  • Use optional chaining for the module-level require.extensions?.['.js'] access (prevents crash at evaluation time)
  • Add if (!require.extensions) return guards to registerHook and deregisterHook (defensive early-exit when the hook API is unavailable)
  • No behaviour change on Node versions where require.extensions is always defined

Fixes #92935

…Yarn PnP

Node.js v24.15.0 introduced a regression (nodejs/node#61769) where the
`require` function exposed to CJS modules loaded via the ESM loader no
longer carries the `.extensions` property when the module source comes
through a custom loader (e.g. Yarn PnP zip loader).

This caused a crash at module evaluation time:
  TypeError: Cannot read properties of undefined (reading '.js')
      at require-hook.js:35

The fix guards all `require.extensions` accesses with optional chaining
and adds early-return guards in `registerHook`/`deregisterHook` so the
build degrades gracefully instead of crashing.

No behaviour change on Node versions where `require.extensions` is
always defined.

Fixes vercel#92935
@nextjs-bot
Copy link
Copy Markdown
Contributor

Allow CI Workflow Run

  • approve CI run for commit: ab9a579

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

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

2 participants