<h1 dir="auto">What / Why</h1>

<p dir="auto">For switching different Node.js version, we use symlink for global node_modules.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ls -ld /usr/local/lib/node_modules
/usr/local/lib/node_modules -&gt; /var/packages/Node.js_v16/var/node_modules"><pre class="notranslate">$ ls -ld /usr/local/lib/node_modules
/usr/local/lib/node_modules -<span class="pl-k">&gt;</span> /var/packages/Node.js_v16/var/node_modules</pre></div>
<p dir="auto">The global module directory and npm itself is removed after installing global module.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ npm install -g pino-pretty
npm WARN reify Removing non-directory /usr/local/lib/node_modules"><pre class="notranslate">$ npm install -g pino-pretty
npm WARN reify Removing non-directory /usr/local/lib/node_modules</pre></div>
<p dir="auto">The behavior have been changed from <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36/hovercard" href="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36">npm/arborist@<tt>f2b0cee</tt></a>.</p>
<h2 dir="auto">How</h2>
<h3 dir="auto">Current Behavior</h3>

<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ npm install -g pino-pretty
npm WARN reify Removing non-directory /usr/local/lib/node_modules"><pre class="notranslate">$ npm install -g pino-pretty
npm WARN reify Removing non-directory /usr/local/lib/node_modules</pre></div>
<h3 dir="auto">Steps to Reproduce</h3>

<ol dir="auto">
<li>Make global node_modules be symlink.</li>
<li>Run <code class="notranslate">npm install -g &lt;any module&gt;</code></li>
<li>The global node_modules is removed.</li>
</ol>
<h3 dir="auto">Expected Behavior</h3>

<p dir="auto">Allow global node_modules be symlink.</p>
<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">If I have a symlink called <code class="notranslate">node_modules</code> to a different directory, then npm will remove this symlink and create a real folder. This has been introduced in <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36/hovercard" href="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36">npm/arborist@<tt>f2b0cee</tt></a> as a safety feature, but as it doesn't disable it as specified when using <code class="notranslate">--force</code> option.</p>
<p dir="auto">Other people have similar problems too:</p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="975555398" data-permission-text="Title is private" data-url="https://github.com/npm/cli/issues/3669" data-hovercard-type="issue" data-hovercard-url="/npm/cli/issues/3669/hovercard" href="https://github.com/npm/cli/issues/3669">#3669</a></li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1109143965" data-permission-text="Title is private" data-url="https://github.com/npm/cli/issues/4274" data-hovercard-type="issue" data-hovercard-url="/npm/cli/issues/4274/hovercard" href="https://github.com/npm/cli/issues/4274">#4274</a></li>
</ul>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">It should work as intended in <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36/hovercard" href="https://github.com/npm/arborist/commit/f2b0ceebfe94123f162c3652af46f9c4c473cc36">npm/arborist@<tt>f2b0cee</tt></a> (don't remove symlink if <code class="notranslate">--force</code>).</p>
<p dir="auto">I really needed this thing to work, so I had to downgrade npm to an older version.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>Create an empty folder</li>
<li>Create a second folder inside the first one</li>
<li>Run <code class="notranslate">npm init -y</code></li>
<li>Run <code class="notranslate">ln -s your_folder_name node_modules</code></li>
<li>Run <code class="notranslate">npm install --force &lt;any package name&gt;</code></li>
<li><code class="notranslate">node_modules</code> no longer points to <code class="notranslate">your_folder_name</code></li>
</ol>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>npm: v8.3.1</li>
<li>Node.js: v17.4.0</li>
<li>OS Name: MacOS Catalina</li>
<li>System Model Name: iMac</li>
<li>npm config:</li>
</ul>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="; this only showed comments and registry auth token &quot;(protected)&quot;"><pre class="notranslate"><span class="pl-c"><span class="pl-c">;</span> this only showed comments and registry auth token "(protected)"</span></pre></div>