Repository navigation
workers: --require module injects module to worker thread #28518
Description
Activity
cc @addaleax
- addedworkerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
on Jul 3, 2019 i wouldn't expect this to happen, but it's not exactly a leap to want this behaviour either...
maybe we can add a flag to workers to disallow loading these (default enabled)
Just noting that both
child_process.fork()and theclustermodule behave this way as well.Is this really not expected? This seems to me as if it would be working as intended.
The documentation is, unfortunately, not very clear about side-effects: https://nodejs.org/dist/latest-v12.x/docs/api/cli.html#cli_r_require_module
From the
Workerconstructor options documentation:execArgv{string[]} List of node CLI options passed to the worker. V8 options […] are not supported. If set, this will be provided as [process.execArgv][] inside the worker. By default, options will be inherited from the parent thread.So, yes, inheriting CLI flags is intentional, and there is a way to override this, and I would say that this seems like a documentation visibility issue than a bug?
Reacted by snek and Jan Olaf MartinSo, yes, inheriting CLI flags is intentional, and there is a way to override this, and I would say that this seems like a documentation visibility issue than a bug?
Should we split process-only options (e.g.,
--title) and all other in two different groups in documentation? It will give me explicit signal where each option works. Since from my use case point of view--requireshould be process-only option, but in case of custom module loader it should be process and worker option - it might be source of confusion.In my use case I am not controlling spawning workers or creating child processes, so I can not override it. I can workaround it on my side by checking for worker in required module but I prefer
--process-requireoption that will inject module only to process or maybe some generic option modifier that can make any options process-only, e.g.--process-only --require a.js --proces-only --inspect.- added a commit that references this issue
on Jan 16, 2020 - added a commit that references this issue
on Mar 4, 2020 - added a commit that references this issue
on Mar 30, 2020 - added a commit that references this issue
on Jul 27, 2026
Steps to reproduce:
and b.js:
node --require b.js a.jsI am wondering is it feature or bug that we inject
--requiremodule to workers. If it is feature, should we mention it in workers doc and in--requireflag description?In my use case - I use
--requireto implementinspectorsocket discovery in user land - I need--requireonly for main thread. I can workaround it on my side but do we need some additional flag that will inject to workers instead of reusing existing flag.