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

<p dir="auto"><code class="notranslate">npm install</code> fails to resolve two version ranges of one dependency into a version that is compatible with both requirements.</p>
<p dir="auto">I have to use the unsafe <code class="notranslate">--legacy-peer-deps</code> flag to bypass this error.</p>
<h2 dir="auto">When</h2>
<p dir="auto">I try to add another package to a project with <code class="notranslate">"react": "^16.9.0"</code> I get a conflict, even though the ranges are compatible (<code class="notranslate">peerDependencies</code> of the package being installed is <code class="notranslate">"react": "^0.14.9 || &gt;=15.3.0"</code>).</p>
<h2 dir="auto">How</h2>
<h3 dir="auto">Current Behavior</h3>

<p dir="auto">When resolving peer dependencies, <code class="notranslate">npm</code> picks the latest available edge version of <code class="notranslate">react</code> compatible with the installed <code class="notranslate">peerDependency</code> requirements, which is <code class="notranslate">17.0.2</code> at the moment, ignoring the rest of the range. And then fails with dependency version conflict.</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="mkdir peer-dependency-conflict-demo
cd peer-dependency-conflict-demo
npm add react@^16.9.0
npm add react-bootstrap@=0.32.4"><pre class="notranslate">mkdir peer-dependency-conflict-demo
<span class="pl-c1">cd</span> peer-dependency-conflict-demo
npm add react@^16.9.0
npm add react-bootstrap@=0.32.4</pre></div>
<details><summary>npm ERR! code ERESOLVE</summary>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   react@&quot;^16.14.0&quot; from the root project
npm ERR!   peer react@&quot;^0.14.9 || &gt;=15.3.0&quot; from react-bootstrap@0.32.4
npm ERR!   node_modules/react-bootstrap
npm ERR!     react-bootstrap@&quot;=0.32.4&quot; from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@&quot;17.0.2&quot; from react-dom@17.0.2
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@&quot;^0.14.9 || &gt;=15.3.0&quot; from react-bootstrap@0.32.4
npm ERR!   node_modules/react-bootstrap
npm ERR!     react-bootstrap@&quot;=0.32.4&quot; from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/ivan/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ivan/.npm/_logs/2021-11-17T15_45_03_518Z-debug.log"><pre class="notranslate"><code class="notranslate">npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   react@"^16.14.0" from the root project
npm ERR!   peer react@"^0.14.9 || &gt;=15.3.0" from react-bootstrap@0.32.4
npm ERR!   node_modules/react-bootstrap
npm ERR!     react-bootstrap@"=0.32.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from react-dom@17.0.2
npm ERR! node_modules/react-dom
npm ERR!   peer react-dom@"^0.14.9 || &gt;=15.3.0" from react-bootstrap@0.32.4
npm ERR!   node_modules/react-bootstrap
npm ERR!     react-bootstrap@"=0.32.4" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/ivan/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ivan/.npm/_logs/2021-11-17T15_45_03_518Z-debug.log
</code></pre></div>
</details>
<h3 dir="auto">Expected Behavior</h3>

<p dir="auto">NPM installs the requested package, knowing that the current installed version of <code class="notranslate">react</code> is compatible with its peer requirements (<code class="notranslate">"react": "16.14.0"</code> satisfies <code class="notranslate">^0.14.9 || &gt;=15.3.0</code>).</p>
<h2 dir="auto">References</h2>

<p dir="auto"><a href="https://github.com/react-bootstrap/react-bootstrap/blob/v0.32.4/package.json#L54-L57">https://github.com/react-bootstrap/react-bootstrap/blob/v0.32.4/package.json#L54-L57</a></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">When I execute <code class="notranslate">npm install</code>, It's download the dependencies first but not <code class="notranslate">preinstall</code> script.</p>
<h3 dir="auto">Expected Behavior</h3>
<ol dir="auto">
<li><code class="notranslate">preinstall</code> script run</li>
<li>Download Dependencies as part of the <code class="notranslate">install</code></li>
</ol>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>Touch a file named <code class="notranslate">package.json</code> with script setting <code class="notranslate">"preinstall": "echo preinstall"</code>.</li>
<li>Exec <code class="notranslate">npm install</code> in shell.</li>
<li>Finally you can see that print after download all dependencies.</li>
</ol>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>npm:8.1.4</li>
<li>Node:16.13.0</li>
<li>OS:macOS Monterey 12.0.1</li>
<li>platform:Macbook Pro</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;user&quot; config from /Users/edz/.npmrc

//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:_password = (protected) 
//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:username = &quot;user_1294702425938741&quot; 
//registry.npmjs.org/:_authToken = (protected) 
email = &quot;bittttter@duduyixia.com&quot; 
registry = &quot;https://registry-node.aliyun.com/org/1294702234938741/registry/xdk/&quot; 

; node bin location = /Users/edz/.nvm/versions/node/v16.13.0/bin/node
; cwd = /Users/edz/Documents/work/xdk-wechat-mini/xiaodaka-client
; HOME = /Users/edz"><pre class="notranslate"><span class="pl-c"><span class="pl-c">;</span> "user" config from /Users/edz/.npmrc</span>

//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:<span class="pl-k">_password</span> = (protected) 
//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:<span class="pl-k">username</span> = <span class="pl-s"><span class="pl-pds">"</span>user_1294702425938741<span class="pl-pds">"</span></span> 
//registry.npmjs.org/:<span class="pl-k">_authToken</span> = (protected) 
<span class="pl-k">email</span> = <span class="pl-s"><span class="pl-pds">"</span>bittttter@duduyixia.com<span class="pl-pds">"</span></span> 
<span class="pl-k">registry</span> = <span class="pl-s"><span class="pl-pds">"</span>https://registry-node.aliyun.com/org/1294702234938741/registry/xdk/<span class="pl-pds">"</span></span> 

<span class="pl-c"><span class="pl-c">;</span> node bin location = /Users/edz/.nvm/versions/node/v16.13.0/bin/node</span>
<span class="pl-c"><span class="pl-c">;</span> cwd = /Users/edz/Documents/work/xdk-wechat-mini/xiaodaka-client</span>
<span class="pl-c"><span class="pl-c">;</span> HOME = /Users/edz</span></pre></div>