Skip to content

module: fix require(esm) on the module.register() hooks thread - #66770

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-require-esm-hooks-thread
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-require-esm-hooks-thread

Conversation

@mcollina

@mcollina mcollina commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Since #62530, require() of an ES module that has imports, done while a module.register() hooks module is loading on the hooks thread, fails with ERR_INTERNAL_ASSERTION in ModuleJobSync.syncLink().

#62530 made getOrCreateModuleJob() resolve asynchronously for every request on the hooks thread, and switched kImportInRequiredESM jobs there to ModuleJob. This restores the previous behavior for those request types: kImportInRequiredESM and kRequireInImportedCJS are always resolved synchronously, and kImportInRequiredESM always uses ModuleJobSync. The main-thread behavior from #62530 is unchanged.

Fixes: #66767


AI generated, reviewed by me.

On the async loader hooks thread, resolve kImportInRequiredESM and
kRequireInImportedCJS requests synchronously again, and always use
ModuleJobSync for kImportInRequiredESM. Otherwise require() of an ES
module with imports from a hooks module hit an internal assertion in
ModuleJobSync.syncLink().

Fixes: nodejs#66767
Refs: nodejs#62530
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.51%. Comparing base (1c90519) to head (eb35469).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66770      +/-   ##
==========================================
+ Coverage   90.49%   90.51%   +0.01%     
==========================================
  Files         797      797              
  Lines      277598   277602       +4     
  Branches    53336    53346      +10     
==========================================
+ Hits       251220   251271      +51     
+ Misses      16790    16733      -57     
- Partials     9588     9598      +10     
Files with missing lines Coverage Δ
lib/internal/modules/esm/loader.js 99.90% <100.00%> (+<0.01%) ⬆️

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

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

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

require(esm) inside a module.register() hook module fails with ERR_INTERNAL_ASSERTION in 26.12.0

2 participants