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
Darwin X-MacBook-Pro.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64
Subsystem
module
What steps will reproduce the bug?
Create a customization hook that intercepts resolve and log out the arguments while making some CJS with the patched require from being loaded via ESM; notice that randomly even though it is not possible to resolve to file: you get a file specifier (added some CJS hooks to show better explanation [note _load called differently in non-requirable ESM CJS]):
constModule=require('module');// Save the original loader so we can call it later.constoriginalLoad=Module._load;constoriginalResolveFilename=Module._resolveFilename;Module._resolveFilename=function(request,parent){console.log({_resolveFilename:{request,parent}})return'foo'returnoriginalResolveFilename.apply(this,arguments);};Module._load=function(request,parent,isMain){console.log({_load:{request,parent,isMain}})constexported=originalLoad.apply(this,arguments);returnexported;};letid=1Module.registerHooks({resolve(specifier,context,nextResolve){console.dir({resolve:{specifier,context}},{depth:null})if(specifier.startsWith('file:')){debugger;}return{url: `sea:${id++}`,shortCircuit: true}returnnextResolve(specifier,context)},load(url,context,nextLoad){console.dir({load:{url,context}},{depth:null})return{source: ` if (module.id.endsWith(2)) throw Error('bail'); let dep = "sea:bare/${String(url).slice(4)}" try { require(dep); } catch (error) { // NOTE: this gives a different path to load! console.log('FAILED TO REQUIRE', dep, require.resolve(dep)) } `,format: 'commonjs',shortCircuit: true}}})import('bare')
How often does it reproduce? Is there a required condition?
everytime
What is the expected behavior? Why is that the expected behavior?
CJS (either by default or hooked _resolveFilename resolves to a non-file [e.g. foo]) and then that value is passed into the loader hooks
What do you see instead?
IDEAL: don't need to hook into _resolveFilename to make resolution work; (removing the above monkey patch to _resolveFilename still causes failure)
unify logic of so that instrumentation can properly deduce how to respond
i. due to personal preference I'd suggest if they differ to respect the altered form rather than trying to change it into a file.
ii. There is some odd logic around WASM and JSON that doesn't match either.
Additional information
No response
The text was updated successfully, but these errors were encountered:
I am guessing this has something to do with the resolve hook being run again in the evaluation callback of import(cjs). Recognizing this case and skip the second resolution hook might make it go away.
Version
v23.7.0
Platform
Subsystem
module
What steps will reproduce the bug?
Create a customization hook that intercepts
resolve
and log out the arguments while making some CJS with the patched require from being loaded via ESM; notice that randomly even though it is not possible to resolve tofile:
you get a file specifier (added some CJS hooks to show better explanation [note _load called differently in non-requirable ESM CJS]):How often does it reproduce? Is there a required condition?
everytime
What is the expected behavior? Why is that the expected behavior?
CJS (either by default or hooked _resolveFilename resolves to a non-file [e.g.
foo
]) and then that value is passed into the loader hooksWhat do you see instead?
i. due to personal preference I'd suggest if they differ to respect the altered form rather than trying to change it into a file.
ii. There is some odd logic around WASM and JSON that doesn't match either.
Additional information
No response
The text was updated successfully, but these errors were encountered: