npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.51k stars 3.19k forks source link

[BUG] SIGINT called twice #5021

Open alesmenzel opened 2 years ago

alesmenzel commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

SIGINT is called twice, immediately terminating the process, causing any cleanup code that runs on SIGINT unable to run without hacking around and handling npm double fire or running the process outside of npm run

Expected Behavior

SIGINT is called just once

Steps To Reproduce

// some-script
#!/usr/bin/env node

// just to keep the process running
setInterval(() => {}, 10000)

process.on('SIGINT', () => {
  console.log('SIGINT')
})
// package.json
"scripts": {
  "doSomething": "./some-script"
}

and run it

npm run doSomething

and the output

> <project>@<version> doSomething
> ./do-something

^CSIGINT
SIGINT

Environment

mashirozx commented 2 years ago

Same issue here, with npx ts-node

image
vladkrasn commented 9 months ago

I am not sure if this is the same issue, but I encountered double process termination prompts. It happens on some node/npm versions, but doesn't on others

I encounter this in different projects, for example let's take boilerplate vite project https://vitejs.dev/guide/

Reproduction:

  1. Node v21.6.1, nvm v10.2.4
  2. yarn create vite or pnpm create vite to install. This bug is NOT happening when the project is installed through npm
  3. npm run dev
  4. Ctrl+C
  5. Two "terminate batch" promps image

This also is happening on:

  1. Node v20.11.0, npm v10.2.4
  2. Node v18.19.0, npm v10.2.3

This is not happening on:

  1. Node v19.8.1, npm v9.5.1

System is Windows 11. I use nvm for windows as node version manager, not sure if it causes mess with npm versions