<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">This issue exists in the latest npm version</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I am using the latest npm</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Running <code class="notranslate">npm -g update serverless@pre-3</code> wipes the content of the global node_modules directory (<code class="notranslate">/usr/local/lib/node_modules</code>).</p>
<p dir="auto">Here is a log file of the command: <a href="https://gist.github.com/mnapoli/0170614e3f4ab1915a82783bf871d033">https://gist.github.com/mnapoli/0170614e3f4ab1915a82783bf871d033</a></p>
<p dir="auto">Here is what I tried to pinpoint the problem:</p>
<ul dir="auto">
<li>no problem with a local install (<code class="notranslate">npm update serverless@pre-3</code>)</li>
<li><code class="notranslate">npm -g i pure-prompt</code> works</li>
<li><code class="notranslate">npm -g update pure-prompt</code> works</li>
<li><code class="notranslate">npm -g i serverless</code>  works</li>
<li><code class="notranslate">npm -g update serverless</code> works</li>
<li><code class="notranslate">npm -g i serverless@pre-3</code> works</li>
<li><code class="notranslate">npm -g update serverless@pre-3</code> <g-emoji class="g-emoji" alias="x" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/274c.png">❌</g-emoji> wipes everything</li>
<li><code class="notranslate">yarn global add serverless</code>  works</li>
<li><code class="notranslate">yarn global update serverless@pre-3</code> works</li>
</ul>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Nothing should be removed, the package should be installed.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<p dir="auto">Run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm -g update serverless@pre-3"><pre class="notranslate"><code class="notranslate">npm -g update serverless@pre-3
</code></pre></div>
<p dir="auto">Now all global dependencies are gone (e.g. <code class="notranslate">serverless</code>, <code class="notranslate">npm</code>, etc.). The global folder <code class="notranslate">/usr/local/lib/node_modules</code> still exists, but it's empty.</p>
<p dir="auto">I have to reinstall NPM and reinstall all global NPM dependencies.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>npm: 8.3.0</li>
<li>Node.js: v17.3.1</li>
<li>OS Name: macOS</li>
<li>System Model Name: Bug Sur 11.6.2</li>
<li>npm config:</li>
</ul>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="; &quot;builtin&quot; config from /usr/local/lib/node_modules/npm/npmrc

prefix = &quot;/usr/local&quot;

; &quot;user&quot; config from /Users/matthieu/.npmrc

//npm.pkg.github.com/:_authToken = (protected)
//registry.npmjs.org/:_authToken = (protected)

; node bin location = /usr/local/Cellar/node/17.3.1/bin/node
; cwd = /Users/matthieu/dev/PHP/bref
; HOME = /Users/matthieu
; Run `npm config ls -l` to show all defaults."><pre class="notranslate"><span class="pl-c"><span class="pl-c">;</span> "builtin" config from /usr/local/lib/node_modules/npm/npmrc</span>

<span class="pl-k">prefix</span> = <span class="pl-s"><span class="pl-pds">"</span>/usr/local<span class="pl-pds">"</span></span>

<span class="pl-c"><span class="pl-c">;</span> "user" config from /Users/matthieu/.npmrc</span>

//npm.pkg.github.com/:<span class="pl-k">_authToken</span> = (protected)
//registry.npmjs.org/:<span class="pl-k">_authToken</span> = (protected)

<span class="pl-c"><span class="pl-c">;</span> node bin location = /usr/local/Cellar/node/17.3.1/bin/node</span>
<span class="pl-c"><span class="pl-c">;</span> cwd = /Users/matthieu/dev/PHP/bref</span>
<span class="pl-c"><span class="pl-c">;</span> HOME = /Users/matthieu</span>
<span class="pl-c"><span class="pl-c">;</span> Run `npm config ls -l` to show all defaults.</span></pre></div>
<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>