Skip to content

workers: --require module injects module to worker thread #28518

@alexkozy

Description

@alexkozy
  • Version: v12.5.0
  • Platform: Mac
  • Subsystem: worker_threads

Steps to reproduce:

  1. Create two scripts, a.js:
const { Worker } = require('worker_threads');
const worker = new Worker('console.log(42)', { eval: true, data: {} });

and b.js:

const { isMainThread } = require('worker_threads');
console.log('b', isMainThread);
  1. Run node --require b.js a.js
  2. Take a look on output:
b true
b false
42

I am wondering is it feature or bug that we inject --require module to workers. If it is feature, should we mention it in workers doc and in --require flag description?

In my use case - I use --require to implement inspector socket discovery in user land - I need --require only 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    workerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions