Skip to content

Conversation

@joyeecheung
Copy link
Member

Previously, when require()-ing builtins with the node: prefix, the sync resolve hooks were not properly invoked, and load hooks could not override the builtin's format. This fixes the handling and enables redirecting prefixed built-ins to on-disk files and overriding them with other module types via hooks.

Fixes: #60005

Previously, when require()-ing builtins with the node: prefix,
the sync resolve hooks were not properly invoked, and load hooks
could not override the builtin's format. This fixes the
handling and enables redirecting prefixed built-ins to on-disk
files and overriding them with other module types via hooks.
@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 16, 2025
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (4f24aff) to head (a84209d).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #61088   +/-   ##
=======================================
  Coverage   88.53%   88.53%           
=======================================
  Files         703      703           
  Lines      208546   208590   +44     
  Branches    40217    40228   +11     
=======================================
+ Hits       184634   184675   +41     
+ Misses      15926    15915   -11     
- Partials     7986     8000   +14     
Files with missing lines Coverage Δ
lib/internal/modules/cjs/loader.js 98.11% <100.00%> (+0.13%) ⬆️

... and 41 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.

@ljharb
Copy link
Member

ljharb commented Dec 17, 2025

i'm confused; i thought the prefix was meant to prevent any kind of user intervention in accessing the core module, with require.extensions OR loaders - does this PR change that?

@joyeecheung
Copy link
Member Author

joyeecheung commented Dec 17, 2025

i thought the prefix was meant to prevent any kind of user intervention in accessing the core module, with require.extensions OR loaders - does this PR change that?

module.register already allows customizations of modules prefixed with node: (as far back as 20)

echo "require('node:tls')" > test.cjs
node --import ./test/fixtures/module-hooks/register-logger-async-hooks.mjs test.cjs

resolve file:///Users/joyee/projects/node/test.cjs from undefined
load file:///Users/joyee/projects/node/test.cjs
resolve node:tls from file:///Users/joyee/projects/node/test.cjs
load node:tls

@ljharb
Copy link
Member

ljharb commented Dec 17, 2025

wow, ok, that's unfortunate - that was one of the primary justifications for adding the prefix in the first place, the performance and reliability benefit of not being able to intercept it.

@joyeecheung
Copy link
Member Author

Addressed the comments and fixed the linter complaint. PTAL, thanks! @aduh95

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2025
@github-actions
Copy link
Contributor

Failed to start CI
   ⚠  No approving reviews found
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/20415476248

@github-actions github-actions bot added the request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. label Dec 21, 2025
@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Dec 21, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2025
@nodejs-github-bot
Copy link
Collaborator

@avivkeller avivkeller added the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 22, 2025
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Dec 22, 2025
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/61088
✔  Done loading data for nodejs/node/pull/61088
----------------------------------- PR info ------------------------------------
Title      module: fix sync resolve hooks for require with node: prefixes (#61088)
Author     Joyee Cheung <joyeec9h3@gmail.com> (@joyeecheung)
Branch     joyeecheung:fix-node-hooks -> nodejs:main
Labels     module, author ready, needs-ci
Commits    2
 - module: fix sync resolve hooks for require with node: prefixes
 - fixup! module: fix sync resolve hooks for require with node: prefixes
Committers 1
 - Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61088
Fixes: https://github.com/nodejs/node/issues/60005
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61088
Fixes: https://github.com/nodejs/node/issues/60005
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 16 Dec 2025 14:48:51 GMT
   ✔  Approvals: 1
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/61088#pullrequestreview-3602021967
   ✘  This PR needs to wait 37 more hours to land (or 0 minutes if there is one more approval)
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2025-12-21T22:09:15Z: https://ci.nodejs.org/job/node-test-pull-request/70575/
- Querying data for job/node-test-pull-request/70575/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/20419381566

@marco-ippolito marco-ippolito added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Dec 22, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 22, 2025
@nodejs-github-bot nodejs-github-bot merged commit 28f468a into nodejs:main Dec 22, 2025
82 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 28f468a

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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.

Cannot read properties of undefined when requiring node:fs with hooks

6 participants