Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Given the following packages:
{
"name": "app",
"version": "1.0.0",
"dependencies": {
"a": "^1.0.0",
"b": "^1.0.0"
}
}
{
"name": "a",
"version": "1.0.0",
"peerDependencies": {
"c": "^1.0.0"
},
"peerDependenciesMeta": {
"c": {
"optional": true
}
}
}
{
"name": "b",
"version": "1.0.0",
"dependencies": {
"c": "^2.0.0"
}
}
{
"name": "c"
"version": "1.0.0"
}
{
"name": "c"
"version": "2.0.0"
}
Running npm install in app completes successfully, but results in the following invalid tree (npm ls):
app@1.0.0
├─┬ a@1.0.0
│ └── c@2.0.0 invalid: "^1.0.0" from node_modules/a
└─┬ b@1.0.0
└── c@2.0.0 deduped invalid: "^1.0.0" from node_modules/a
Basically, b's version of c gets incorrectly hoisted, resulting in an incompatible peer dep for a.
npm ci also refuses to install the tree that npm install just generated:
npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
Related to #4664. That issue was closed but there does seem to be an npm bug here.
Expected Behavior
I haven't thought through the details carefully, but it seems that b's dependency on c shouldn't be hoisted if it would result in an invalid optional peer dep.
Steps To Reproduce
This reproduces in npm 8.6.0 through 8.9.0.
- Clone https://github.com/billyjanitsch/npm-optional-peer-deps-hoist
- Note the two separate commits. The first commits the package.json, and the second commits the package-lock.json generated by
npm install.
- Run
npm ci or npm ls; both exit with an error.
@pmmmwh/react-refresh-webpack-plugin@0.5.5 optionally peer-depends on type-fest@>=0.17.0 <3.0.0. ow directly depends on type-fest@^0.11.0. The latter gets incorrectly hoisted.
Environment
- npm: 8.9.0
- Node.js: 16.15.0
- OS Name: macOS
- System Model Name: MacBook Pro
- npm config:
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Given the following packages:
{ "name": "app", "version": "1.0.0", "dependencies": { "a": "^1.0.0", "b": "^1.0.0" } }{ "name": "a", "version": "1.0.0", "peerDependencies": { "c": "^1.0.0" }, "peerDependenciesMeta": { "c": { "optional": true } } }{ "name": "b", "version": "1.0.0", "dependencies": { "c": "^2.0.0" } }{ "name": "c" "version": "1.0.0" }{ "name": "c" "version": "2.0.0" }Running
npm installinappcompletes successfully, but results in the following invalid tree (npm ls):Basically,
b's version ofcgets incorrectly hoisted, resulting in an incompatible peer dep fora.npm cialso refuses to install the tree thatnpm installjust generated:Related to #4664. That issue was closed but there does seem to be an npm bug here.
Expected Behavior
I haven't thought through the details carefully, but it seems that
b's dependency oncshouldn't be hoisted if it would result in an invalid optional peer dep.Steps To Reproduce
This reproduces in npm 8.6.0 through 8.9.0.
npm install.npm ciornpm ls; both exit with an error.@pmmmwh/react-refresh-webpack-plugin@0.5.5optionally peer-depends ontype-fest@>=0.17.0 <3.0.0.owdirectly depends ontype-fest@^0.11.0. The latter gets incorrectly hoisted.Environment
; n/a