-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.argv vanishing when --import flag used #50719
Comments
Could you share a minimal repro? Please note that images makes it very hard fir folks using screen reader, or those unable to decipher text with your color scheme – it also makes it pointlessly harder to copy paste your code to debug the issue. |
@aduh95 Thanks for looking, so the only thing to see in the screenshots is the commands being run, which are: // loader.js
if(process.execArgv.some(flag=>flag.startsWith("--import")))
// register loader module.
await Promise.all(["module","worker_threads"].map(module=>
import(module))).then(([{register},{MessageChannel}])=>
[new MessageChannel(),import.meta.url].reduce(({port1,port2},parentURL)=>
register(new URL(parentURL).pathname,parentURL,{data:{socket:port2},transferList:[port2]})));
else console.trace(process.argv);
export function initialize({socket}){console.trace(process.argv);socket.postMessage("Module interface ready");}
export function resolve(source,context,next){console.trace(process.argv);return next(source,context);} expected logs: |
I think it is your responsibility to pass the argv from the main thread to the loader thread. /cc @nodejs/loaders |
@aduh95 ah right argv are actually intact on the main thread - i just got used to the main thread running the resolution with the old --loader flag, and thought the worker was only alive during the loader registration/initialization. It all actually remains on a separate thread now, got it. So it's a similar reason to why that --watch flag disappears from execArgv on the main thread itself too. Now i'll just need to figure out how to get the result of what i use the argv for in module resolution back to the main thread somehow... hope it's possible. Thanks! |
Version
20.9.0
Platform
linux-x64
I'm trying to upgrade from the old --loader to the new --import flag for module customization hooks now, but i'm encountering an issue with process.argv going missing when the --import flag is used (both in the loader registration worker, and the main process), unlike without the flag being used:
( for full picture, this is where the hooks get called in each case: )
I have seen similar occur with the --watch flag not being present in execArgv when used, but that is less critical and i can imagine a reason for it.
Is there a reason for process.argv disappearing with --import modules?
Tested with Node 20.9 and 21.1, happens in both versions.
Additional information
first reported under --import flag's concluded feature request: #40110 (comment)
The text was updated successfully, but these errors were encountered: