Title: CJS module customized by synchronous customization hooks uses synthetic `require` with any use of `--loader` · Issue #63060 · nodejs/node · GitHub
Open Graph Title: CJS module customized by synchronous customization hooks uses synthetic `require` with any use of `--loader` · Issue #63060 · nodejs/node
X Title: CJS module customized by synchronous customization hooks uses synthetic `require` with any use of `--loader` · Issue #63060 · nodejs/node
Description: Version All versions 24.12.0 ~ 24.15.0 and 25.2.0 ~ 25.9.0 Platform Linux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux Subsystem module What steps will reproduce the bug? // hook.cj...
Open Graph Description: Version All versions 24.12.0 ~ 24.15.0 and 25.2.0 ~ 25.9.0 Platform Linux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux Subsystem module What ...
X Description: Version All versions 24.12.0 ~ 24.15.0 and 25.2.0 ~ 25.9.0 Platform Linux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux Subsystem module What ...
Opengraph URL: https://github.com/nodejs/node/issues/63060
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CJS module customized by synchronous customization hooks uses synthetic `require` with any use of `--loader`","articleBody":"### Version\n\nAll versions 24.12.0 ~ 24.15.0 and 25.2.0 ~ 25.9.0\n\n### Platform\n\n```text\nLinux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux\n```\n\n### Subsystem\n\nmodule\n\n### What steps will reproduce the bug?\n\n```javascript\n// hook.cjs\nrequire('module').registerHooks({\n load(url, context, next) {\n return url.endsWith('entry.js') ? {\n source: 'console.log(\"intercepted\", require.cache)',\n format: 'commonjs',\n shortCircuit: true\n } : next(url, context)\n }\n})\n```\n\nplus empty files `empty.mjs` and `entry.js`\n\n```shell\n$ node --no-warnings -r ./hooks.cjs --loader ./empty.mjs ./entry.js\n```\n\n### How often does it reproduce? Is there a required condition?\n\nAlways\n\n### What is the expected behavior? Why is that the expected behavior?\n\nLogs:\n1. `intercepted`, showing the loading of `entry.js` was customized by the synchronous `load` hook\n2. The `require.cache` object\n\nThe [docs](https://nodejs.org/docs/v25.9.0/api/module.html#asynchronous-loadurl-context-nextload) mention, in part, under \"Asynchronous `load(url, context, nextLoad)`\":\n\n\u003e When a `source` is provided, [...] only a subset of the CommonJS API will be available (e.g. no `require.extensions`, no `require.cache`, no `require.resolve.paths`) and monkey-patching on the CommonJS module loader will not apply.\n\u003e These caveats do not apply to the synchronous `load` hook, in which case the complete set of CommonJS APIs available to the customized CommonJS modules\n\nThis is, as far as I can tell, the only mention of this \"synthetic `require`\" behavior. And it should not apply to this case as the module is only customized by a synchronous `load` hook. There are no asynchronous customization hooks registered.\n\n### What do you see instead?\n\nLogs: `intercepted undefined`\n\nThis shows `entry.js` is using the synthetic `require`, despite what the docs say.\n\nThe mere *use* of the `--loader` flag triggers this, even when using empty file as a loader (so no asynchronous customization hooks are registered). Using `module.register` to register a loader file behaves the same as the `--loader` flag. The only way to avoid the synthetic `require` behvaior is to not use `--loader` or `module.register` at all.\n\n### Additional information\n\nFor a few weeks now I have been trying to migrate Yarn to synchronous customization hooks in response to #62012. The current stopgap we introduced in Yarn 4.14.0 falls into the documented caveats of \"synthetic `require`\" mentioned above. See https://github.com/nodejs/node/issues/62012#issuecomment-4282758016\n\nThe issue reported here means that to properly fix to #62012 on our end, we can't just move module loading via our fs patch layer to synchronous hooks. Instead we must do an all-or-nothing migration from `--loader` into `module.registerHooks`.","author":{"url":"https://github.com/clemyan","@type":"Person","name":"clemyan"},"datePublished":"2026-05-01T04:07:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/63060/node/issues/63060"}
| 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:69b0464e-be99-1175-17e0-205b5ceb39dd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBE6:1070C6:F6EBEE:14DF5A7:6A4C66A5 |
| html-safe-nonce | c1f040346c48f6eb53c0d0a1855bc082f22aeec611e10e4191a7446c20484991 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkU2OjEwNzBDNjpGNkVCRUU6MTRERjVBNzo2QTRDNjZBNSIsInZpc2l0b3JfaWQiOiIzNzc4MzczMzkwMjQ0Mjc1ODc3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 166983998724210f195611d1444bb22ba5c4f6f2b29187f3b5e699e8b0f6c24c |
| hovercard-subject-tag | issue:4362736839 |
| 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/63060/issue_layout |
| twitter:image | https://opengraph.githubassets.com/383100258de75caf5ff702e5647b9ee93b4da567b17c9a6628e5cc23dc0e054f/nodejs/node/issues/63060 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/383100258de75caf5ff702e5647b9ee93b4da567b17c9a6628e5cc23dc0e054f/nodejs/node/issues/63060 |
| og:image:alt | Version All versions 24.12.0 ~ 24.15.0 and 25.2.0 ~ 25.9.0 Platform Linux 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux Subsystem module What ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | clemyan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| 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 | 14099438da5379150f15a2892474c7c7e6c0e55e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width