Skip to content

[BUG] Downgrading to previous npm version deletes all global packages. #3671

@dtoch

Description

@dtoch

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Downgrading npm 7.21.0 to a previous 7.x version causes all global packages to be deleted.

Expected Behavior

Downgrading npm 7.21.0 to a previous 7.x version should not delete all global packages.

Steps To Reproduce

A. Installed a clean node 14.17.5 installation (https://nodejs.org/dist/v14.17.5/node-v14.17.5-win-x64.zip) on Windows 10 in c:\temp\node. To avoid side-effects :

  • no custom $HOME/.npmrc present (so will use default settings)
  • no %AppData%\Local\npm-cache and neither %AppData%\Roaming\npm-cache present

B. Then in a DOS shell:

$set PATH=c:\temp\node;%PATH% 

$node -v
v14.17.5

$npm -v
6.14.14

Until now OK.

C. Then I wanted to upgrade npm to the latest version (7.21.0):

Because npm update -g npm@latest does nothing and npm install -g npm@latest fails with "File exists: c:\temp\node\npm.cmd", I used following procedure to upgrade to npm@latest (based on https://try2explore.com/questions/10972799):

$cd c:\temp\node

$move npm npm-old
$move npm.cmd npm-old.cmd
$move npx npx-old
$move npx.cmd npx-old.cmd

$cd node_modules
$move npm npm-old
$cd npm-old\bin
$node npm-cli.js i -g npm@latest

$npm -v
7.21.0

Until now OK.

D. Now I wanted to downgrade npm to [email protected]:

$npm update -g [email protected]

removed 691 packages, and audited 1 package in 9s

found 0 vulnerabilities
The batch file cannot be found.

Result :

c:\temp\node\node_modules now completely empty! Also if I first would have installed other global packages (verdaccio, yeoman, ...), then they would also have disappeared from c:\temp\node\node_modules.

Above procedure was performed in a DOS shell but I also encountered the same issue in a Powershell 7 shell.

Environment

  • OS: Windows 10
  • Node: 14.7.5 (includes npm 6.14.14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 7.xwork is associated with a specific npm 7 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions