Skip to content

[BUG] npm fails to install optional dependencies of peer dependencies #8487

@billyjanitsch

Description

@billyjanitsch

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

Suppose my package A depends on package B which peer-depends on package C which optionally depends on package D.

As of npm@11.5, npm install does not install D nor write it to the package lock.

This was introduced in #8431, which intended to prune optional peer dependencies. But optional peer dependencies are not the same as optional dependencies of peer dependencies, and this PR as written also affects the latter.

Expected Behavior

npm install should install D, as it did prior to npm@11.5.0.

Steps To Reproduce

  1. Create a new package A which depends on package B which peer-depends on package C which optionally depends on package D.
  2. Run npm install.
  3. Observe that D does not exist in the package lock or node_modules.

Environment

  • npm: 11.5.2
  • Node.js: 22.18.0
  • OS Name: macOS
  • System Model Name: MacBook Pro
  • npm config: default

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