You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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.
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'}
The text was updated successfully, but these errors were encountered:
I'm trying to use the module hooks/loader with SEA, to distribute my project, in 1+n files.
Where the node.js binary will be injected with a custom hook/loader, and then load and run code in one or more ASAR archives.
This requires the hooks to resolve and load paths that do not really exist on the hard drive.
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
node/lib/internal/modules/esm/translators.js
Lines 130 to 159 in 69f8794
The resolving of the
specifier
is done in the main thread, usingModule._resolveFilename
, before being sent to the customization hooks.The resolver hook is then receiving a resolved
file://
URL, instead of the realspecifier
.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:
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.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'}
The text was updated successfully, but these errors were encountered: