Skip to content

[BUG/REGRESSION] should not install optional peer dependencies #9139

@Gouvernathor

Description

@Gouvernathor

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 a project with package A version X installed.
Given a package B having an optional peer dependency on package A version Y.
When installing package B, npm tries to install A version Y. If X and Y are incompatible versions, the install fails.
Additionnaly, the install still fails when explicitly passing --omit=optional.

Expected Behavior

Optional dependencies, including optional peer dependencies, should not be installed, especially when they would cause a conflict with already-installed packages.

Previous discussion

See issue #2615 which was supposed to solve the exact same problem in npm version 7.5.5, apparently the fix has been reverted since then.
Also see broader discussion here, and there.

Steps To Reproduce

  1. In an Angular project version 21 (at least 21.2.2 reproduces the problem)
  2. Run npm install parliamentarch@3.1.0, or npm install parliamentarch@3.1.0 --omit=optional
  3. See error Conflicting peer dependency: jsdom@25.0.1

Environment

  • OS Name: Windows
  • System Model Name: 11
  • npm config:
; node version = v24.12.0
; npm version = 11.10.0
; Run `npm config ls -l` to show all defaults.

(private information omitted)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions