npm / npm/cli

[BUG] Ctrl+Cing npm update uninstalls everything

Open
#5,006 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
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)
image
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.