-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
worker_threads and NODE_OPTIONS #29117
Comments
Tangential: it sounds like implementing #27501 (module archive support) would also fix your issue. |
@arcanis Can you share a reproduction? As far as I can tell, Repro setup, click to expandtest.js: 'use strict';
const { Worker, isMainThread } = require('worker_threads');
if (isMainThread)
new Worker(__filename); preload.js: 'use strict';
console.log('preload module', require('worker_threads').threadId); Run in shell: $ node --require ./preload.js test.js
preload module 0
preload module 1
$ NODE_OPTIONS='--require ./preload.js' node test.js
preload module 0
preload module 1 Each print twice, as they should, once for each Node.js instance |
Hey @addaleax! Sorry for the (very 🙃) late answer. I've just investigated more and the problem appears if you make the following change to your code (which seems to be what Parcel is doing): new Worker(__filename, {execArgv: process.execArgv}); In this case, the preload won't be executed anymore as cc @mischnic |
@arcanis Hey! Thanks for the update … however, with only that modification, I still can’t reproduce the issue (neither with Node.js master nor v12.3.1). Is there something else that turns |
I've put the repro here: https://github.com/arcanis/node-options-execargv Running
Removing the
|
Ah, I see – sorry, this was kind of my bad. The issue is that So I guess the question is whether |
Imo it should, because users would have a way to override this behaviour if they wish to by explicitly removing the key from the environment before passing it to the const env = {...process.env};
delete env.NODE_OPTIONS;
new Worker(..., {
execArgv: [],
env,
}); |
This should now work with or without the Feel free to reopen if I missed anything. |
process._preload_modules
should be forwarded to the workersThis one is a bit convoluted ... first some context:
--require /path/to/.pnp.js
.pnp.js
extends thefs
module to add support for in-zip readingworker_threads
if possibleIt works fine with
child_process.fork
, because under the regular CLI the--require
scripts are executed before the entry point is resolved (except when using--inspect
if I remember correctly), so by the timerunMain
is called the zip archives can be accessed.However, with
worker_threads
it seems that the NODE_OPTIONS--require
entries are completely ignored andrunMain
is called directly, causing the script to be executed outside of the PnP context and thus not being able to access its dependencies or even spawn if stored within a zip archive (which is the case by default, although it can be disabled).The text was updated successfully, but these errors were encountered: