Skip to content

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

Open
semimikoh wants to merge 2 commits intonodejs:mainfrom
semimikoh:fix/worker-node-options-env
Open

worker: parse NODE_OPTIONS when env option is not provided#62306
semimikoh wants to merge 2 commits 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.66%. Comparing base (4d2d6de) to head (9f345a9).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #62306    +/-   ##
========================================
  Coverage   89.66%   89.66%            
========================================
  Files         676      676            
  Lines      206575   206693   +118     
  Branches    39555    39583    +28     
========================================
+ Hits       185225   185339   +114     
+ Misses      13501    13495     -6     
- Partials     7849     7859    +10     
Files with missing lines Coverage Ξ”
src/node_worker.cc 81.31% <100.00%> (-0.10%) ⬇️

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

@mertcanaltin
Copy link
Member

Thank you, could you add a test for this?

@semimikoh
Copy link
Contributor Author

@mertcanaltin

Added a test in 9f345a9. It verifies that NODE_OPTIONS set at runtime are picked up by a worker when the env option is not provided.

Copy link
Member

@mertcanaltin mertcanaltin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

3 participants