module: preserve URL in the parent created by createRequire()
Previously, createRequire() does not preserve the URL it gets passed in the mock parent module created, which can be observable if it's used together with module.registerHooks(). This patch adds preservation of the URL if createRequire() is invoked with one.
Fixes: https://github.com/nodejs/node/issues/60973
Review requested:
- [ ] @nodejs/loaders
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 88.51%. Comparing base (644fb88) to head (a66fbbd).
:warning: Report is 70 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #60974 +/- ##
==========================================
- Coverage 88.51% 88.51% -0.01%
==========================================
Files 703 703
Lines 208394 208438 +44
Branches 40193 40206 +13
==========================================
+ Hits 184470 184505 +35
- Misses 15934 15940 +6
- Partials 7990 7993 +3
| Files with missing lines | Coverage Δ | |
|---|---|---|
| lib/internal/modules/cjs/loader.js | 98.02% <100.00%> (+<0.01%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Thank you for your quick fix! I was wondering if this PR can be backported to v22 or v24?
It should be back portable after staying in 25 for a few weeks (per LTS policy), the code touched is not the in usual volatile parts of the module loader but in the implementation of createRequire() which is fairly stable so there should be little conflicts.
CI: https://ci.nodejs.org/job/node-test-pull-request/70416/
CI: https://ci.nodejs.org/job/node-test-pull-request/70429/
CI: https://ci.nodejs.org/job/node-test-pull-request/70432/
Commit Queue failed
- Loading data for nodejs/node/pull/60974 ✔ Done loading data for nodejs/node/pull/60974 ----------------------------------- PR info ------------------------------------ Title module: preserve URL in the parent created by createRequire() (#60974) Author Joyee Cheung <[email protected]> (@joyeecheung) Branch joyeecheung:fix-create-require-url -> nodejs:main Labels module, needs-ci, review wanted Commits 1 - module: preserve URL in the parent created by createRequire() Committers 1 - Joyee Cheung <[email protected]> PR-URL: https://github.com/nodejs/node/pull/60974 Fixes: https://github.com/nodejs/node/issues/60973 Reviewed-By: Benjamin Gruenbaum <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/60974 Fixes: https://github.com/nodejs/node/issues/60973 Reviewed-By: Benjamin Gruenbaum <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Sat, 06 Dec 2025 05:36:14 GMT ✔ Approvals: 1 ✔ - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/60974#pullrequestreview-3548026675 ✘ This PR needs to wait 12 more hours to land (or 0 hours if there is one more approval) ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-12-08T16:06:54Z: https://ci.nodejs.org/job/node-test-pull-request/70432/ - Querying data for job/node-test-pull-request/70432/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/20174007589
Landed in 4f24aff94ad9160bceaf9dcc9cf5235a65f01029