-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Bugthing that needs fixingthing that needs fixingPriority 1high priority issuehigh priority issueRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 release
Description
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
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):
[email protected]
├─┬ [email protected]
│ └── [email protected] invalid: "^1.0.0" from node_modules/a
└─┬ [email protected]
└── [email protected] 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 ciornpm ls; both exit with an error.
@pmmmwh/[email protected] 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:
; n/aAliMirlou, kschat, Diamondlord, JooshTaylor, szmarczak and 6 more
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingPriority 1high priority issuehigh priority issueRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 release