Skip to content

[worker_threads] inherited --vfs-load is skipped when --import is present #66270

Description

@januththedev

Version

v24.x main

Proposed change

A worker that inherits parent execArgv should apply an inherited --vfs-load mount before resolving its entry file, including when the parent also uses --import.

Current behavior

lib/internal/main/worker_thread.js only calls finishVfsMounts() before loading the worker when there are no imports:

if (imports.length === 0) {
  finishVfsMounts()
}

The file-worker path reaches Module.runMain(filename), which calls resolveMainPath() before runEntryPointWithESMLoader() installs the inherited VFS mount. A worker entry inside the inherited VFS therefore fails to resolve when the parent command also contains --import.

Steps to reproduce

Create noop.mjs, then:

// app/index.js
const path = require('node:path')
const {Worker} = require('node:worker_threads')

new Worker(path.join(__dirname, 'worker.js'))
  .on('message', console.log)
  .on('error', console.error)
// app/worker.js
require('node:worker_threads').parentPort.postMessage('ok')

Run:

node --experimental-vfs --import ./noop.mjs --vfs-load ./app

Expected: the worker loads app/worker.js from the inherited VFS and prints ok.

Actual: worker entry resolution happens before the inherited mount is installed, so loading fails.

Regression test

Extend test/parallel/test-vfs-load.js with the existing inherited-worker scenario and an otherwise empty --import preload.

I found no existing issue or PR covering --vfs-load together with --import for inherited workers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions