Skip to content

[BUG] failed to resolve peer dependencies (conflict) when peer dependencies are in range. #3152

Description

@talsi

Current Behavior:

npm install favors getting higher versions of peer dependencies.

for example:

"@angular/cdk": 10.2.5 has the following peer dependencies

{
  ...
  "@angular/common": "^10.0.0 || ^11.0.0-0",
  "@angular/core": "^10.0.0 || ^11.0.0-0"
  ...
}

"@angular/forms": 10.2.5 has the following peer dependencies

{
  ...
  "@angular/common": "10.2.5",
  "@angular/core": "10.2.5"
  ...
}

if you try to install both packages above you'll get an error because when resolving peer dependencies it chooses "@angular/common": 11.2.11 (and then "@angular/core": 11.2.11) thus results in a conflict

Expected Behavior:

when resolving peer dependencies it should choose "@angular/common": 10.2.5 (and then "@angular/core": 10.2.5) that would have satisfy all deps

Steps To Reproduce:

  1. open an empty project / folder
  2. run npm init (package.json doesn't list any dependencies)
  3. run npm i @angular/cdk@10.2.5 @angular/forms@10.2.5

result:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @angular/core@11.2.11
npm ERR! node_modules/@angular/core
npm ERR!   peer @angular/core@"^10.0.0 || ^11.0.0-0" from @angular/cdk@10.2.5
npm ERR!   node_modules/@angular/cdk
npm ERR!     @angular/cdk@"10.2.5" from the root project
npm ERR!   peer @angular/core@"11.2.11" from @angular/common@11.2.11
npm ERR!   node_modules/@angular/common
npm ERR!     peer @angular/common@"^10.0.0 || ^11.0.0-0" from @angular/cdk@10.2.5
npm ERR!     node_modules/@angular/cdk
npm ERR!       @angular/cdk@"10.2.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @angular/forms@"10.2.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@10.2.5
npm ERR! node_modules/@angular/core
npm ERR!   peer @angular/core@"10.2.5" from @angular/forms@10.2.5
npm ERR!   node_modules/@angular/forms
npm ERR!     @angular/forms@"10.2.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

image

Environment:

npm: 7.11.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 7.xwork is associated with a specific npm 7 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions