Skip to content

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

Open
@noseratio

Description

@noseratio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions