Skip to content

worker_threads and NODE_OPTIONS #29117

@arcanis

Description

@arcanis
  • Version: 12.3.1
  • Platform: all
  • Subsystem: workers
  • Tl;dr: process._preload_modules should be forwarded to the workers

This one is a bit convoluted ... first some context:

  • Yarn 2 keeps the vendors within zip archives instead of unpacking them
  • To make it work, NODE_OPTIONS contains --require /path/to/.pnp.js
  • This .pnp.js extends the fs module to add support for in-zip reading
  • Parcel 2, a vendor (and thus stored within a zip), uses worker_threads if possible

It 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 time runMain is called the zip archives can be accessed.

However, with worker_threads it seems that the NODE_OPTIONS --require entries are completely ignored and runMain 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).

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