Skip to content

Document more clearly that --require and --import can impact all threads and forked processes #52930

@timfish

Description

@timfish

Affected URL(s)

https://nodejs.org/api/cli.html#-r---require-module

Description of the problem

There was a previous issue for this:
#28518

But the PR to improve this does not make this clear in the right places:
#31380

When using these args, it's important to understand their impact.

My understanding is that these arguments impact:

  • The main thread (obvious!)
  • All worker threads unless you specifically pass execArgv: [] to options
  • All processes created by child_process.fork() unless you pass execArgv: [] to options
  • All processes created by the cluster module unless you pass `execArgv: [], to settings

As requested in the previous issues, this behaviour should really be documented under --require docs here:
https://nodejs.org/api/cli.html#-r---require-module

and also for the --import docs here:
https://nodejs.org/api/cli.html#--importmodule

It might also be worth linking to this warning from both of those args because this is information is key and hidden right at the bottom of the worker thread docs:
https://nodejs.org/api/worker_threads.html#launching-worker-threads-from-preload-scripts

Metadata

Metadata

Assignees

No one assigned

    Labels

    cliIssues and PRs related to the Node.js command line interface.docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions