Title: require.extensions is undefined on synthetic require for CJS loaded through ESM loader (regression in v24.15.0) · Issue #62786 · nodejs/node · GitHub
Open Graph Title: require.extensions is undefined on synthetic require for CJS loaded through ESM loader (regression in v24.15.0) · Issue #62786 · nodejs/node
X Title: require.extensions is undefined on synthetic require for CJS loaded through ESM loader (regression in v24.15.0) · Issue #62786 · nodejs/node
Description: Version v24.15.0 (fails). Works on v24.14.1 and earlier. Platform: Linux x64 (also reproduced inside node:24.15.0-slim Docker image). Platform Linux x64 Subsystem loaders, module, specifically the CJS-from-ESM translator (node:internal/m...
Open Graph Description: Version v24.15.0 (fails). Works on v24.14.1 and earlier. Platform: Linux x64 (also reproduced inside node:24.15.0-slim Docker image). Platform Linux x64 Subsystem loaders, module, specifically the ...
X Description: Version v24.15.0 (fails). Works on v24.14.1 and earlier. Platform: Linux x64 (also reproduced inside node:24.15.0-slim Docker image). Platform Linux x64 Subsystem loaders, module, specifically the ...
Opengraph URL: https://github.com/nodejs/node/issues/62786
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"require.extensions is undefined on synthetic require for CJS loaded through ESM loader (regression in v24.15.0)","articleBody":"### Version\n\nv24.15.0 (fails). Works on v24.14.1 and earlier. Platform: Linux x64 (also reproduced inside `node:24.15.0-slim` Docker image).\n\n### Platform\n\n```text\nLinux x64\n```\n\n### Subsystem\n\n`loaders`, `module`, specifically the CJS-from-ESM translator (`node:internal/modules/esm/translators`).\n\n### What steps will reproduce the bug?\n\n**Reproducer repo:** https://github.com/kabo/node-24.15-require-extensions-repro\n\n```sh\ngit clone https://github.com/kabo/node-24.15-require-extensions-repro\ncd node-24.15-require-extensions-repro/variant-b\ntouch yarn.lock\ncorepack yarn install\ncorepack yarn node run.mjs # crashes on v24.15.0; succeeds on v24.14.1\n```\n\nThe reproducer is ~10 lines of code split across 4 files: a Yarn 4.14.1 PnP project (`package.json`), an ESM entry (`run.mjs`) that does `await import('dummy-cjs')`, and a trivial local CJS dependency (`dummy-cjs/index.cjs`) whose only relevant line is:\n\n```js\nconst oldJSHook = require.extensions['.js'] // line that throws on v24.15.0\n```\n\nSee the repo's `README.md` for full context, and `output-variant-b-24.14.0.txt` / `output-variant-b-24.15.0.txt` for the side-by-side outputs that establish the regression.\n\n\n### How often does it reproduce? Is there a required condition?\n\nEvery time on v24.15.0 when a CJS file is loaded via the ESM loader through a custom resolver/loader that produces a non-file URL (Yarn PnP loads from `file://.../cache/....zip/node_modules/...`).\n\n\n### What is the expected behavior? Why is that the expected behavior?\n\n`require.extensions` should be defined on the `require` function passed into the CJS module wrapper. It is deprecated (DEP0007) but has been part of the public `require` surface since 0.12. Multiple libraries still in active use (Next.js `next-config-ts/require-hook.js`, ts-node, esbuild-register, pirates, etc.) read it at CJS module top level.\n\nConfirmed behavior on v24.14.1:\n\n```\nnode: v24.14.1\ntypeof require.extensions: object\n.js hook: function\n```\n\n\n### What do you see instead?\n\nOn v24.15.0:\n\n```\n[dummy-cjs] node: v24.15.0\n[dummy-cjs] typeof require: function\n[dummy-cjs] typeof require.extensions: undefined\nfile:///.../.yarn/berry/cache/dummy-cjs-file-6872e80d06-10.zip/node_modules/dummy-cjs/index.cjs:6\nconst oldJSHook = require.extensions['.js']\n ^\n\nTypeError: Cannot read properties of undefined (reading '.js')\n at Object.\u003canonymous\u003e (file:///.../.yarn/berry/cache/dummy-cjs-file-6872e80d06-10.zip/node_modules/dummy-cjs/index.cjs:6:37)\n at loadCJSModule (node:internal/modules/esm/translators:185:3)\n at ModuleWrap.\u003canonymous\u003e (node:internal/modules/esm/translators:231:7)\n at ModuleJob.run (node:internal/modules/esm/module_job:437:25)\n at process.processTicksAndRejections (node:internal/process/task_queues:104:5)\n at async node:internal/modules/esm/loader:639:26\n at async file:///.../run.mjs:1:1\n\nNode.js v24.15.0\n```\n\nNote `typeof require` is `function` — a `require` is provided — but `require.extensions` is `undefined` on it, which differs from what CJS modules (and the `Module.prototype.require` used in filesystem-loaded CJS) see.\n\n\n### Additional information\n\n- **Suspected cause**: [nodejs/node#61769](https://github.com/nodejs/node/pull/61769) (\"lib: reduce cycles in esm loader and load it in snapshot\"), which rewrote the ESM loader initialization and the synthesised `require` construction for CJS-from-ESM. That PR landed in v24.x for the first time in v24.15.0.\n- **Related bug in same subsystem**: [nodejs/node#62012](https://github.com/nodejs/node/issues/62012) — EBADF fstat on zip fds in the same `createCJSModuleWrap` path. Same Node version, same Yarn PnP setup, different symptom in the same synthetic-CJS-wrap code.\n- **Real-world impact**: `next build` on Next.js 15+ fails for all users on Yarn PnP + Node 24.15 because Next's [`next/dist/build/next-config-ts/require-hook.js`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/next-config-ts/require-hook.ts#L35) reads `require.extensions['.js']` at module top level.\n- **Not reproducible** when the CJS file is loaded from a filesystem path (without a custom PnP-like loader in front), which suggests the bug is specific to how the ESM→CJS wrap constructs `require` for modules whose source URL is not a plain `file:///.../something.cjs`.\n- **Likely also affects v25.7+** since PR #61769 landed on v25 first.\n\n## Workaround\n\n- Downgrade to Node v24.14.1.\n- Or, for library authors reading `require.extensions`: use optional chaining (`require.extensions?.['.js']`) so the call at module load doesn't throw.\n","author":{"url":"https://github.com/kabo","@type":"Person","name":"kabo"},"datePublished":"2026-04-17T10:43:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/62786/node/issues/62786"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:69764a58-1b7d-2c84-c089-f2cd469bca8f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9858:6A6D7:2C4F03D:3EFE856:6A4CFEDB |
| html-safe-nonce | 0ecb51817d163ce3b6502fc544645702baf6b585e1a4d9f8dd44cead96c982b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODU4OjZBNkQ3OjJDNEYwM0Q6M0VGRTg1Njo2QTRDRkVEQiIsInZpc2l0b3JfaWQiOiIyMTk2ODU0Njg1Mzk4MDA3NTE1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 193a60e86ddf26afbe1dbfce7074abdd6c943fc5af5a18a7e1d9870ab7a7a708 |
| hovercard-subject-tag | issue:4281998001 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/62786/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c9f556cc945c51bccf2de573e7954c49558553b158ccc434bd87c008231656a/nodejs/node/issues/62786 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c9f556cc945c51bccf2de573e7954c49558553b158ccc434bd87c008231656a/nodejs/node/issues/62786 |
| og:image:alt | Version v24.15.0 (fails). Works on v24.14.1 and earlier. Platform: Linux x64 (also reproduced inside node:24.15.0-slim Docker image). Platform Linux x64 Subsystem loaders, module, specifically the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kabo |
| hostname | github.com |
| expected-hostname | github.com |
| None | 31e4db13a9e20081f2fac78f441659a6576e582bbb15e153f9c7fb6473aa29f5 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fb70bd3c4b2bec429781b65419e912c66e2d5581 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width