Title: Sync `resolve` hook does not affect `require.resolve()` · Issue #62692 · nodejs/node · GitHub
Open Graph Title: Sync `resolve` hook does not affect `require.resolve()` · Issue #62692 · nodejs/node
X Title: Sync `resolve` hook does not affect `require.resolve()` · Issue #62692 · nodejs/node
Description: Version v24.14.0 Platform Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 25H2 Home Edition build 26200.8037) Subsystem node:module What steps will reproduce the bug? Extending the code @joyeecheung wrote in her initial PR for register...
Open Graph Description: Version v24.14.0 Platform Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 25H2 Home Edition build 26200.8037) Subsystem node:module What steps will reproduce the bug? Extending the code @joyeeche...
X Description: Version v24.14.0 Platform Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 25H2 Home Edition build 26200.8037) Subsystem node:module What steps will reproduce the bug? Extending the code @joyeeche...
Opengraph URL: https://github.com/nodejs/node/issues/62692
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sync `resolve` hook does not affect `require.resolve()`","articleBody":"### Version\n\nv24.14.0\n\n### Platform\n\n```text\nMicrosoft Windows NT 10.0.26200.0 x64 (Windows 11 25H2 Home Edition build 26200.8037)\n```\n\n### Subsystem\n\nnode:module\n\n### What steps will reproduce the bug?\n\nExtending the code @joyeecheung wrote in her initial PR for `registerHooks` (#55698):\n\n```js\nimport assert from 'node:assert';\nimport { registerHooks, createRequire } from 'node:module';\nimport { writeFileSync } from 'node:fs';\n\nwriteFileSync('./bar.js', 'export const id = 123;', 'utf8');\n\nregisterHooks({\n resolve(specifier, context, nextResolve) {\n const replaced = specifier.replace('foo', 'bar');\n return nextResolve(replaced, context);\n },\n load(url, context, nextLoad) {\n const result = nextLoad(url, context);\n return {\n ...result,\n source: result.source.toString().replace('123', '456'),\n };\n },\n});\n\n// Checks that it works with require.\nconst require = createRequire(import.meta.url);\nconst required = require('./foo.js'); // redirected by resolve hook to bar.js\nassert.strictEqual(required.id, 456); // replaced by load hook to 456\n\n// Checks that it works with import.\nconst imported = await import('./foo.js'); // redirected by resolve hook to bar.js\nassert.strictEqual(imported.id, 456); // replaced by load hook to 456\n\n// ADDED\nconsole.log(import.meta.resolve('./foo.js')) // ✅ prints the file: url of bar.js\nconsole.log(require.resolve('./foo.js')) // 🚫 MODULE_NOT_FOUND ./foo.js\n```\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\nThe last `console.log` statement should print the file path of `bar.js`.\n\n### What do you see instead?\n\n`MODULE_NOT_FOUND` thrown.\n\n### Additional information\n\nThis [comment](https://github.com/nodejs/node/pull/55698#issuecomment-2809007734) did notice the bug already but it seems it didn't get any traction.","author":{"url":"https://github.com/Septh","@type":"Person","name":"Septh"},"datePublished":"2026-04-11T13:52:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/62692/node/issues/62692"}
| 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:4b967785-0e24-9612-5e32-8ee3fe8fe96f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8128:2D98C9:F576A6:15C2160:6A4CB2A9 |
| html-safe-nonce | ddc775023b90e7c411106ba69b4bdd00e3ac4592848cb2ce10a65531916c3178 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTI4OjJEOThDOTpGNTc2QTY6MTVDMjE2MDo2QTRDQjJBOSIsInZpc2l0b3JfaWQiOiI0ODI4MzM2ODgyNTk1MDY4NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 319ae1cdf07f55e6c470119c5308b2bd04c3abf8853b2102a34bc8be4d1bf925 |
| hovercard-subject-tag | issue:4244755605 |
| 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/62692/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb11f747185055dc4ddd115be910bf1e7f8b754104f265f7c4245e899fe4b8df/nodejs/node/issues/62692 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb11f747185055dc4ddd115be910bf1e7f8b754104f265f7c4245e899fe4b8df/nodejs/node/issues/62692 |
| og:image:alt | Version v24.14.0 Platform Microsoft Windows NT 10.0.26200.0 x64 (Windows 11 25H2 Home Edition build 26200.8037) Subsystem node:module What steps will reproduce the bug? Extending the code @joyeeche... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Septh |
| 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 | ae90d426644ca15e89bacceb72e51f4e9dbf85f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width