npm / npm/cli

[BUG] Ctrl-C / SIGINT kills NPM while the Node app keeps running in the background

Open
#7,511 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

On Windows, if Node.js app handles SIGINT, npm exits before the Node app does:

delay.mjs:

process.on('SIGINT', () => {
  console.log("ctrl+c pressed");
});

console.log("sleeping...");
await new Promise(r => setTimeout(r, 5000));
console.log("exiting gracefully");

package.js:

{
  "name": "ctrl-c",
  "main": "delay.mjs",
  "scripts": {
    "start": "node delay.mjs"
  }
}

Running it:

PS C:\temp\ctrl-c> npm start
> start
> node delay.mjs
sleeping...
ctrl+c pressed
PS C:\temp\ctrl-c> exiting gracefully

PS C:\temp\ctrl-c>

Note how the Node app still writes to the console after npm has terminated.

Expected Behavior

The desired behavior is as on Linux, where npm exits only when the Node app has ended.

Steps To Reproduce

See above

Environment
  • npm:
    v10.7.0

  • Node.js:
    v22.1.0

  • OS Name:
    Microsoft Windows 11 Pro [Version 10.0.22631.3527]

  • PowerShell:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
  • npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\Master\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v22.1.0
; npm local prefix = C:\temp\ctrl-c
; npm version = 10.7.0
; cwd = C:\temp\ctrl-c
; HOME = C:\Users\Master
; Run `npm config ls -l` to show all defaults.

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 with the delay.mjs and package.js reproduction and run npm start on Windows, then compare the Ctrl-C behavior with Linux. Trace when npm exits relative to the Node app's SIGINT handler and five-second delay. Done means npm remains running until the Node app prints "exiting gracefully" and terminates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.