Skip to content

[BUG] v11.6.1 fails to install optionalDependencies of inner package (even if build works) #8628

@otaviojacobi

Description

@otaviojacobi

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

  1. Inside the parent directory run:
  2. npm install
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions