nodejs / nodejs/node

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

未关闭
#61,740 7 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

confirmed-bug watch-mode
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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/.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 NODE_OPTIONS="--watch" 重现可执行入口点命令,并将其与 issue #51159 进行比较。跟踪可执行文件和 package bin 入口点的 watch 模式处理,然后添加或更新回归测试;完成的标准是该命令打印一次 hello 后退出,且不生成进程。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
cli, developer-experience
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。