-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Open
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps
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
If we have two packages, for example,
package child
:
{
"name": "child-package-repro",
"version": "1.0.3",
"optionalDependencies": {
"pg": "^8.16.3"
}
}
and package parent
:
{
"name": "parent-package",
"version": "1.0.0",
"dependencies": {
"child-package-repro": "1.0.3"
}
}
When npm install
on the parent package, if it contains a package-lock.json
(generated with previous versions) with the optionalDependency (which is marked as optional) it will completely remove the pg dependency. More over, this worked fine in v11.6.0 and before.
Expected Behavior
The optional dependency pg
should be installed in parent/node_modules/child-package/node_modules/pg
(or hoisted to parent/node_modules/pg
).
Steps To Reproduce
With this package: https://github.com/otaviojacobi/npm-cli-repro
- Inside the
parent
directory run: - npm install
npm ls pg
will result with:
❯ npm ls pg
parent-package@1.0.0 /home/repro/parent
└── (empty)
While if you install with any previous version of npm (11.6.0 or lower):
❯ npm ls pg
parent-package@1.0.0 /home/repro/parent
└─┬ child-package-repro@1.0.3
└─┬ pg@8.16.3
└─┬ pg-pool@3.10.1
└── pg@8.16.3 deduped
My understanding is that this issue is coming from #8579 which is causing a optionalDependency to be removed from the final tree.
Environment
No response
pichlermarc, alecarn and MikeJeffersthgreasi
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps