cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] `npm update -g ds` removes all global packages and npm itself

Open ealexandrohin opened this issue 1 year ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

Title. Basically self-destructs and purges all global packages and you can't even run npm after. As I have tested, it works with any package that is not installed, even non-existent ones.

npm update -g [non-installed package]

To fix it, you need to re-install whole Node again with nvm.

Expected Behavior

Don't self-destruct and delete all global packages, when you specify package that is not installed.

Steps To Reproduce

  1. run npm update -g ds
  2. get the result
removed 203 packages in 641ms
The batch file cannot be found.
  1. try to run npm again npm -v
'npm' is not recognized as an internal or external command,
operable program or batch file.
  1. become aware of your unimportance to the universe

Environment

  • npm: probably was 10.8.2, but I cannot check it because npm itself doesn't exist anymore.
  • Node.js: 22.6.0 (64-bit) via nvm
  • OS Name: Windows 10
  • npm config: cannot give you, as stated above.

ealexandrohin avatar Aug 18 '24 20:08 ealexandrohin

npm update should never be run with -g.

ljharb avatar Aug 18 '24 23:08 ljharb

npm update should never be run with -g.

but how you should update your global packages then?

ealexandrohin avatar Aug 29 '24 21:08 ealexandrohin

One at a time, manually, with npm install. (also you probably shouldn't have any global packages)

ljharb avatar Aug 29 '24 22:08 ljharb

Here's the log I saw, hopefully it helps others find this issue:

PS C:...> npm i -g tsc
npm ERR! code EEXIST
npm ERR! path C:\Users\admin\AppData\Roaming\npm\tsc
npm ERR! File exists: C:\Users\admin\AppData\Roaming\npm\tsc
npm ERR! with --force to overwrite files recklessly.

npm ERR!     C:\Users\admin\AppData\Local\npm-cache\_logs\2024-10-14T15_28_08_921Z-debug.log
PS C:...> npm update -g tsc
removed 2019 packages, and audited 1 package in 8s

PS C:...> npm update -g tsc
npm error Class extends value undefined is not a constructor or null

For me, fixing it required uninstalling nvm before reinstalling node the proper way (perhaps reinstalling node through nvm would work too).

rsxdalv avatar Oct 15 '24 13:10 rsxdalv