Skip to content

esm: allow worker file entries with --input-type - #68001

Open
danielroe wants to merge 1 commit into
nodejs:mainfrom
danielroe:fix/worker-input-type
Open

danielroe wants to merge 1 commit into
nodejs:mainfrom
danielroe:fix/worker-input-type

Conversation

@danielroe

@danielroe danielroe commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

currently, a process started with --input-type can't start a worker from a file.

example

echo 'console.log("worker ok")' > /tmp/w.mjs
node --input-type=module -e 'const { Worker } = await import("node:worker_threads"); new Worker("/tmp/w.mjs")'
Error [ERR_INPUT_TYPE_NOT_ALLOWED]: --input-type can only be used with string input via --eval, --print, or STDIN
    at defaultResolve (node:internal/modules/esm/resolve:967:49)

the issue is that the worker inherits --input-type from the parent's exec arguments. that's useful for eval workers (since #54979), so I haven't dropped it, but instead just limited the check/error to the main thread's entry.

Note

I'm ignoring an explicit new Worker(file, { execArgv: ['--input-type=module'] }), just like node --input-type=module file.cjs on the main thread, but ... let me know if you think that's wrong.

related: unjs/env-runner#115

Workers inherit the parent's execArgv, including --input-type, which
decides how eval workers run. A worker's file entry point has no
parent URL, so it hit the ERR_INPUT_TYPE_NOT_ALLOWED check meant for
the main entry point. Only apply that check on the main thread.

Signed-off-by: Daniel Roe <daniel@roe.dev>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Dec 3, 2026
@danielroe danielroe changed the title esm: allow worker file entries with --input-type esm: allow worker file entries with --input-type Dec 3, 2026
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.57%. Comparing base (fdd741c) to head (a90ccb5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #68001      +/-   ##
==========================================
- Coverage   92.97%   90.57%   -2.41%     
==========================================
  Files         432      802     +370     
  Lines      201316   287005   +85689     
  Branches    30713    55429   +24716     
==========================================
+ Hits       187172   259943   +72771     
- Misses      13817    17156    +3339     
- Partials      327     9906    +9579     
Files with missing lines Coverage Δ
lib/internal/modules/esm/resolve.js 100.00% <100.00%> (ø)

... and 505 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants