Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Unexpected behavior in module customization hooks / loader, for `require` | GoodFirstPicks

Unexpected behavior in module customization hooks / loader, for `require`

nodejs/node 6 comments 1mo ago
View on GitHub
highopenScope: somewhat clearSkill match: noNode.jsJavaScript

Why this is a good first issue

The issue involves deep architectural changes and maintainer feedback suggests significant complexity.

AI Summary

The issue describes unexpected behavior in module customization hooks related to `require`, specifically around the resolution of CJS specifiers and the handling of `file://` URLs. The maintainers indicate that the current approach may be fundamentally flawed and suggest reverting to previous methods. This requires deep architectural knowledge and understanding of Node.js internals, making it a complex and high-risk issue.

Issue Description

It seems I am one of the early adopters of module hooks. I liked the idea of the module customization hooks, and tried to use it in my project. However, I believe the current behavior of require handling in the esm loader is buggy.

Relevant source code, here https://github.com/nodejs/node/blob/69f8794cbea5813ff9abb490c2cd875b8332f605/lib/internal/modules/esm/translators.js#L130-L159

The resolving of the specifier is done in the main thread, using Module._resolveFilename, before being sent to the customization hooks. The resolver hook is then receiving a resolved file:// URL, instead of the real specifier.

These are not expected according to the documentation of the module customization hooks. And for my use case, it has made the hooks useless.

To make it clear there are two bugs:

  1. The cjs specifiers are being resolved in the wrong thread.
    The hooks, therefore, cannot really work, because if the "expected" file does not really exist on the hard drive. The cjs Module._resolveFilename will throw an error in the first place.
  2. The resolve hook is receiving a wrong specifier, if the first bug would not trigger.

The root of this issue might be the default resolver in customization hooks does not support resolving CJS modules. An easy fix would be to move the Module._resolveFilename into the default resolver. The loading of .node native add-ons may also get in the way. But IMO it should also go through the hooks, and eventually be loaded as {type: 'commonjs', source: undefined, url: 'file://... .node'}

GitHub Labels

loaders

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • deep architectural knowledge required
  • maintainer feedback indicates complexity
Loading labels...

Details

Points10 pts
Difficultyhigh
Scopesomewhat clear
Skill Matchno
Test Focusedno