Issue 1:
What / Why

npm install fails to resolve two version ranges of one dependency into a version that is compatible with both requirements.

I have to use the unsafe --legacy-peer-deps flag to bypass this error.

When

I try to add another package to a project with "react": "^16.9.0" I get a conflict, even though the ranges are compatible (peerDependencies of the package being installed is "react": "^0.14.9 || >=15.3.0").

How

Current Behavior

When resolving peer dependencies, npm picks the latest available edge version of react compatible with the installed peerDependency requirements, which is 17.0.2 at the moment, ignoring the rest of the range. And then fails with dependency version conflict.

Steps to Reproduce

mkdir peer-dependency-conflict-demo
cd peer-dependency-conflict-demo
npm add react@^16.9.0
npm add react-bootstrap@=0.32.4

npm ERR! code ERESOLVE

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 || >=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 || >=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

Expected Behavior

NPM installs the requested package, knowing that the current installed version of react is compatible with its peer requirements ("react": "16.14.0" satisfies ^0.14.9 || >=15.3.0).

References

https://github.com/react-bootstrap/react-bootstrap/blob/v0.32.4/package.json#L54-L57

Issue 2:
Is there an existing issue for this?

I have searched the existing issues

This issue exists in the latest npm version

I am using the latest npm

Current Behavior

When I execute npm install, It's download the dependencies first but not preinstall script.

Expected Behavior

preinstall script run

Download Dependencies as part of the install

Steps To Reproduce

Touch a file named package.json with script setting "preinstall": "echo preinstall".

Exec npm install in shell.

Finally you can see that print after download all dependencies.

Environment

npm:8.1.4

Node:16.13.0

OS:macOS Monterey 12.0.1

platform:Macbook Pro

npm config:

; "user" config from /Users/edz/.npmrc

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

; 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