[BUG] Ctrl+Cing npm update uninstalls everything
Nobody has claimed this yet.
- 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
(I was using npm 8.3.1 at first, updated to 8.12.1 and issue persisted)

I wanted to update a package I am using called mlogx.
I mistyped the command as npm up -g mlog
I did not want to install a random package, so I pressed Ctrl+C and told windows not to terminate the batch job.
Several seconds after I pressed Ctrl+C npm outputs "Removed 1426 packages."
Everything's gone.
I'm pretty sure you're not supposed to ctrl+c npm, but uninstalling all packages is the worst thing that can happen short of a vulnerability.
Expected Behavior
Either terminate/abort the command or install/update the mlog package.
Steps To Reproduce
Run npm up -g (some package that you don't have installed)
Quickly press Ctrl+C and then type n
It removes all your globally installed packages. Reproduced twice.
Environment
- npm: 8.12.1
- Node.js: 16.14.0
- OS Name: Windows
- System Model Name: Lenovo Flex 14API
- npm config:
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc
prefix = "C:\\Users\\[username]\\AppData\\Roaming\\npm"
; "user" config from C:\Users\[username]\.npmrc
//registry.npmjs.org/:_authToken = (protected)
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\Bala\Mindustry\logic
; HOME = C:\Users\[username]
; Run `npm config ls -l` to show all defaults.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce on Windows with npm 8.12.1 and Node.js 16.14.0 using a global update for an uninstalled package, then press Ctrl+C and answer n. Trace the npm global update cancellation path; done means aborting this flow no longer removes globally installed packages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100