Skip to content

worker: parse NODE_OPTIONS when env option is not provided#62306

Open
semimikoh wants to merge 1 commit intonodejs:mainfrom
semimikoh:fix/worker-node-options-env
Open

worker: parse NODE_OPTIONS when env option is not provided#62306
semimikoh wants to merge 1 commit intonodejs:mainfrom
semimikoh:fix/worker-node-options-env

Conversation

@semimikoh
Copy link
Contributor

When env option is not explicitly provided to new Worker(),
runtime changes to process.env.NODE_OPTIONS (e.g. adding --import)
are not picked up by the worker thread.

This happens because in node_worker.cc, the NODE_OPTIONS parsing
block is gated behind args[1]->IsObject() || args[2]->IsArray().
When env is not provided, args[1] is null (cloned from
process.env), so the condition is false and NODE_OPTIONS parsing
is skipped entirely.

This fix adds args[1]->IsNull() to the condition so that
NODE_OPTIONS is also parsed when the env is inherited (cloned)
from the parent process.

Fixes: #62301

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support. labels Mar 18, 2026
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (4d2d6de) to head (a352178).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62306      +/-   ##
==========================================
+ Coverage   89.66%   89.68%   +0.01%     
==========================================
  Files         676      676              
  Lines      206575   206575              
  Branches    39555    39558       +3     
==========================================
+ Hits       185225   185262      +37     
+ Misses      13501    13452      -49     
- Partials     7849     7861      +12     
Files with missing lines Coverage Δ
src/node_worker.cc 81.31% <100.00%> (-0.10%) ⬇️

... and 50 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

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to Worker support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node:worker_threads does not load --import file.js unless explicitly setting env option

2 participants