nodejs / nodejs/node

watch: `NODE_OPTIONS=--watch` causes infinite loop

Open
#61,740 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

confirmed-bug watch-mode
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v25.6.0

Platform
Darwin <redacted> 24.6.0 Darwin Kernel Version 24.6.0: Wed Nov  5 21:33:58 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6000 arm64 arm Darwin
Subsystem

No response

What steps will reproduce the bug?
  1. Write the following to test.js and make it executable:
    #!/usr/bin/env node
    console.log('hello');
    
  2. NODE_OPTIONS="--watch" ./test.js
How often does it reproduce? Is there a required condition?

This is always reproducible.

What is the expected behavior? Why is that the expected behavior?

I would expect it to run normally, producing hello in stdout and then exiting.

What do you see instead?

There is no output. I can see in my process list that there are hundreds of node processes spawning.

Additional information

This seems to be the same issue as https://github.com/nodejs/node/issues/51159. For additional context, my intent was to reuse a bin entrypoint in package.json but with --watch mode, so under the scripts field it looked roughly like:

"scripts": {
    "dev": "NODE_OPTIONS='--watch' app",
}

...where app is in node_modules/.bin/.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the executable-entrypoint command with NODE_OPTIONS="--watch" and compare it with issue #51159. Trace the watch-mode handling of the executable and package bin entrypoint, then add or update a regression test; done means the command prints hello once and exits without spawning processes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.