[worker_threads] inherited --vfs-load is skipped when --import is present #66270
Description
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 ./appExpected: 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
inoway46 commentedon Sep 28, 2026
I tested this against the latest official releases: https://github.com/inoway46/node/actions/runs/36371175567
The reported worker.js case does not reproduce on v26.10.0. v24.21.0 does not support --experimental-vfs / --vfs-load.
The extensionless worker case does reproduce with VFS + --import, but that appears to be a separate issue. Closing this one.