Is there an existing issue for this?
This issue exists in the latest npm version
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
[email protected] /home/repro/parent
└── (empty)
While if you install with any previous version of npm (11.6.0 or lower):
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
Is there an existing issue for this?
This issue exists in the latest npm version
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 installon the parent package, if it contains apackage-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
pgshould be installed inparent/node_modules/child-package/node_modules/pg(or hoisted toparent/node_modules/pg).Steps To Reproduce
With this package: https://github.com/otaviojacobi/npm-cli-repro
parentdirectory run:npm ls pgwill result with:While if you install with any previous version of npm (11.6.0 or lower):
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