npm / npm/cli

[BUG/REGRESSION] should not install optional peer dependencies

Open
#9,139 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

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

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the install in an Angular 21 project with npm 11.10.0, both with and without --omit=optional, using parliamentarch@3.1.0. Trace why the optional peer dependency on jsdom is resolved despite the omit flag; done means the install completes without conflicting with the already-installed package.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.