Skip to content

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

Open
sleitor wants to merge 2 commits into
vercel:canaryfrom
sleitor:fix-92935
Open

fix(require-hook): guard require.extensions accesses for Node 24.15+ Yarn PnP#92967
sleitor wants to merge 2 commits into
vercel:canaryfrom
sleitor:fix-92935

Conversation

@sleitor

@sleitor sleitor commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

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

@sleitor

sleitor commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Hey 👋 just checking in on this one — the linked issue is still open and the fix is ready. Would love a review when you get a chance, or any feedback if there are concerns with the approach. Happy to close if there's already a plan to address this differently. Thanks!

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