<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">Create this package in an empty directory:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;name&quot;: &quot;missing-fs-extra&quot;,
  &quot;private&quot;: true,
  &quot;description&quot;: &quot;A simple package to reproduce missing dependencies when installing with the --production flag&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;dependencies&quot;: {
    &quot;gatsby&quot;: &quot;^4.4.0&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@storybook/react&quot;: &quot;^6.4.9&quot;
  },
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;scripts&quot;: {
    &quot;build&quot;: &quot;gatsby build&quot;
  }
}"><pre class="notranslate"><code class="notranslate">{
  "name": "missing-fs-extra",
  "private": true,
  "description": "A simple package to reproduce missing dependencies when installing with the --production flag",
  "version": "0.1.0",
  "dependencies": {
    "gatsby": "^4.4.0"
  },
  "devDependencies": {
    "@storybook/react": "^6.4.9"
  },
  "license": "MIT",
  "scripts": {
    "build": "gatsby build"
  }
}
</code></pre></div>
<p dir="auto">Then attempt to run:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm install --production &amp;&amp; npm run build"><pre class="notranslate"><code class="notranslate">npm install --production &amp;&amp; npm run build
</code></pre></div>
<p dir="auto">Notice how <code class="notranslate">fs-extra</code> which is a direct dependency of <code class="notranslate">gatsby</code> is missing from the installed node-modules. <code class="notranslate">fs-extra</code> is also a direct dependency (with a mismatched version) of <code class="notranslate">@storybook/react</code>, however <code class="notranslate">@storybook/react</code> is a <code class="notranslate">devDependency</code> so my understanding is that it should be ignored completely when installing with the <code class="notranslate">--production</code> flag.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto"><code class="notranslate">fs-extra</code> should be installed in <code class="notranslate">node_modules</code> because it is a direct dependency of <code class="notranslate">gatsby</code> which is a direct dependency of the root package.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>Using <code class="notranslate">npm</code> version 8.3.0</li>
<li>With this package:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;name&quot;: &quot;missing-fs-extra&quot;,
  &quot;private&quot;: true,
  &quot;description&quot;: &quot;A simple package to reproduce missing dependencies when installing with the --production flag&quot;,
  &quot;version&quot;: &quot;0.1.0&quot;,
  &quot;dependencies&quot;: {
    &quot;gatsby&quot;: &quot;^4.4.0&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;@storybook/react&quot;: &quot;^6.4.9&quot;
  },
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;scripts&quot;: {
    &quot;build&quot;: &quot;gatsby build&quot;
  }
}"><pre class="notranslate"><code class="notranslate">{
  "name": "missing-fs-extra",
  "private": true,
  "description": "A simple package to reproduce missing dependencies when installing with the --production flag",
  "version": "0.1.0",
  "dependencies": {
    "gatsby": "^4.4.0"
  },
  "devDependencies": {
    "@storybook/react": "^6.4.9"
  },
  "license": "MIT",
  "scripts": {
    "build": "gatsby build"
  }
}
</code></pre></div>
<ol start="3" dir="auto">
<li>Run <code class="notranslate">npm install --production</code></li>
<li>Notice the <code class="notranslate">fs-extra</code> module is missing from the installed modules, and when gatsby runs (<code class="notranslate">npm run build</code>) it fails to resolve the dependency.</li>
</ol>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>npm: 8.3.0</li>
<li>Node: v14.18.2</li>
<li>OS: MacOS Catalina 10.15.7 (19H1615)</li>
<li>platform: MacbookPro</li>
<li>npm config:</li>
</ul>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="; node bin location = /Users/fernandotoledo/.nvm/versions/node/v14.18.2/bin/node
; cwd = /Users/fernandotoledo/Desktop/test
; HOME = /Users/fernandotoledo
; Run `npm config ls -l` to show all defaults."><pre class="notranslate"><span class="pl-c"><span class="pl-c">;</span> node bin location = /Users/fernandotoledo/.nvm/versions/node/v14.18.2/bin/node</span>
<span class="pl-c"><span class="pl-c">;</span> cwd = /Users/fernandotoledo/Desktop/test</span>
<span class="pl-c"><span class="pl-c">;</span> HOME = /Users/fernandotoledo</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">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">If a package contains a node_modules that is symlinked then an npm install will  issue the message<br>
npm WARN reify Removing non-directory ....<br>
and delete the node_modules directory.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">A symlinked node_modules directory should be used as is and not recreated - many people symlink node_modules to a local filesystem so that it does not get synced to cloud storage (like Dropbox).</p>
<p dir="auto">I suspect that the npm code is just checking if any existing file object named node_modules is a directory and does not also check to see if the non-directory file object is actually a symlinked directory.</p>
<h3 dir="auto">Steps To Reproduce</h3>
<p dir="auto">cd /tmp<br>
mkdir symlinked<br>
mkdir z<br>
cd z<br>
npm init -y<br>
ln -s /tmp/symlinked node_modules .<br>
npm install lodash</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Ubuntu 20.04.1</li>
<li>Node: 16.7</li>
<li>npm: 7.21.0</li>
</ul>