[BUG] On Windows a plain `node server.js` script outlives npm

Đang mở
#287 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@azchohfi đang làm issue này rồi.

Từ ngày 21/11/2026.

  • #288 của @azchohfi — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, node.js
Lĩnh vực
backend, cli

Hướng nghiên cứu

Start by tracing how @npmcli/run-script launches lifecycle scripts on Windows and how it distinguishes plain executable commands from shell syntax, .cmd bins, and builtins. Reproduce the issue with the PowerShell steps in the report, then find the relevant existing tests and add coverage for the command cases described. Done means a plain executable script stops with npm while the listed shell commands retain their current behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

On macOS npm start with "start": "node server.js" ends up as npm's direct child, because /bin/sh execs a lone command. Stop npm and the server stops too.

On Windows the script runs as cmd.exe /d /s /c node server.js. libuv's job object kills npm's children when npm dies, but it sets SILENT_BREAKAWAY_OK, so only cmd.exe is in the job. Stop npm with Stop-Process or taskkill without /T and node keeps running with the port open. Coding agents hit this all the time with dev servers.

Expected Behavior

The change runs a script that is a single .exe with plain arguments without cmd.exe, much like sh does. Scripts with cmd syntax (&&, pipes, redirects, quotes, %VAR%), .cmd bins and builtins are unchanged. One process less per script, and the server goes away with npm (25 of 25 runs). Start-up time doesn't change measurably. Tests included, coverage stays at 100%.

Steps To Reproduce
# package.json: "scripts": { "start": "node server.js" }
$p = Start-Process node -ArgumentList "$env:ProgramFiles\nodejs\node_modules\npm\bin\npm-cli.js", 'start' -PassThru
Stop-Process -Id $p.Id
Get-NetTCPConnection -LocalPort 8765 -State Listen   # still there
Environment
  • npm: 11.19.0, and @npmcli/run-script main (4d116d5) for the change
  • Node.js: 26.7.0
  • OS: Windows 11 x64, PowerShell 7.6
  • npm config: defaults
Ngôn ngữ chính
JavaScript
Star
60
Fork
29
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của npm/run-script

Tất cả issue của npm/run-script

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.