Skip to content

Conversation

@joyeecheung
Copy link
Member

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: #60973

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.
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Dec 6, 2025
@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.51%. Comparing base (644fb88) to head (a66fbbd).
⚠️ Report is 31 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%) ⬆️

... and 51 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sxzz
Copy link
Contributor

sxzz commented Dec 6, 2025

Thank you for your quick fix! I was wondering if this PR can be backported to v22 or v24?

@joyeecheung
Copy link
Member Author

joyeecheung commented Dec 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect parentURL for registerHooks when using require(esm)

4 participants