<h3 dir="auto">Is there an existing issue for this?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the existing issues</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Downgrading npm 7.21.0 to a previous 7.x version causes all global packages to be deleted.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Downgrading npm 7.21.0 to a previous 7.x version should not delete all global packages.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<p dir="auto">A. Installed a clean node 14.17.5 installation (<a href="https://nodejs.org/dist/v14.17.5/node-v14.17.5-win-x64.zip" rel="nofollow">https://nodejs.org/dist/v14.17.5/node-v14.17.5-win-x64.zip</a>) on Windows 10 in c:\temp\node. To avoid side-effects :</p>
<ul dir="auto">
<li>no custom $HOME/.npmrc present (so will use default settings)</li>
<li>no %AppData%\Local\npm-cache and neither %AppData%\Roaming\npm-cache present</li>
</ul>
<p dir="auto">B. Then in a DOS shell:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$set PATH=c:\temp\node;%PATH% 

$node -v
v14.17.5

$npm -v
6.14.14"><pre class="notranslate"><code class="notranslate">$set PATH=c:\temp\node;%PATH% 

$node -v
v14.17.5

$npm -v
6.14.14
</code></pre></div>
<p dir="auto">Until now OK.</p>
<p dir="auto">C. Then I wanted to upgrade npm to the latest version (7.21.0):</p>
<p dir="auto">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 <a href="https://try2explore.com/questions/10972799" rel="nofollow">https://try2explore.com/questions/10972799</a>):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$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"><pre class="notranslate"><code class="notranslate">$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
</code></pre></div>
<p dir="auto">Until now OK.</p>
<p dir="auto">D. Now I wanted to downgrade npm to npm@7.20.3:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$npm update -g npm@7.20.3

removed 691 packages, and audited 1 package in 9s

found 0 vulnerabilities
The batch file cannot be found."><pre class="notranslate"><code class="notranslate">$npm update -g npm@7.20.3

removed 691 packages, and audited 1 package in 9s

found 0 vulnerabilities
The batch file cannot be found.
</code></pre></div>
<p dir="auto">Result :</p>
<p dir="auto">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.</p>
<p dir="auto">Above procedure was performed in a DOS shell but I also encountered the same issue in a Powershell 7 shell.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Windows 10</li>
<li>Node: 14.7.5 (includes npm 6.14.14)</li>
</ul>
<h3 dir="auto">Current Behavior:</h3>
<p dir="auto">Attempting to update a package with a tag using the <code class="notranslate">update</code> command globally causes <strong>ALL</strong> global packages to be removed.</p>
<h3 dir="auto">Expected Behavior:</h3>
<p dir="auto">Packages should not be removed when updating global packages.</p>
<h3 dir="auto">Steps To Reproduce:</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="npm i -g typescript nodemon @angular/cli # Install some global packages
npm ls -g --depth=0 # This shows the 3 installed packages
npm update -g @angular/cli@latest # Attempt to update one of the packages with a @latest tag
# Oh no! removed 620 packages
npm ls -g --depth=0 # Shows `-- (empty)"><pre class="notranslate">npm i -g typescript nodemon @angular/cli <span class="pl-c"><span class="pl-c">#</span> Install some global packages</span>
npm ls -g --depth=0 <span class="pl-c"><span class="pl-c">#</span> This shows the 3 installed packages</span>
npm update -g @angular/cli@latest <span class="pl-c"><span class="pl-c">#</span> Attempt to update one of the packages with a @latest tag</span>
<span class="pl-c"><span class="pl-c">#</span> Oh no! removed 620 packages</span>
npm ls -g --depth=0 <span class="pl-c"><span class="pl-c">#</span> Shows `-- (empty)</span></pre></div>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: Windows 10 20H2</li>
<li>Node: 15.9.0</li>
<li>npm: 7.11.2</li>
</ul>
<h3 dir="auto">Additional Info</h3>
<p dir="auto">This only happens on the global scope</p>