Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install angular library - unable to resolve dependency tree

Some time ago I've pulled my generic code from my angular application into libraries. Now it seems that I'm unable to install a library targetting @angular/[email protected] into a newly created application which also targets 13.1.

Library package.json

{
  "name": "@xxx/ng-animations",
  "private": false,
  "version": "13.1.3",
  "peerDependencies": {
    "@angular/common": "^13.1.0",
    "@angular/core": "^13.1.0"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  }
}

Brand new application package.json

{
  ...,
  "dependencies": {
    "@angular/animations": "~13.1.0",
    "@angular/common": "~13.1.0",
    "@angular/compiler": "~13.1.0",
    "@angular/core": "~13.1.0",
    "@angular/forms": "~13.1.0",
    "@angular/platform-browser": "~13.1.0",
    "@angular/platform-browser-dynamic": "~13.1.0",
    "@angular/router": "~13.1.0",
    "rxjs": "~7.4.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.1.3",
    "@angular/cli": "~13.1.3",
    "@angular/compiler-cli": "~13.1.0",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.10.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.5.2"
  }
}

Somehow this causes the following version conflict error which I'm unable to resolve (I resolved some of these in the past)

npm i @mintplayer/ng-animations
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @angular/[email protected]
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"~13.1.0" from the root project
npm ERR!   peer @angular/core@"^13.1.0" from @mintplayer/[email protected]
npm ERR!   node_modules/@mintplayer/ng-animations
npm ERR!     @mintplayer/ng-animations@"*" from the root project
npm ERR!   1 more (@angular/animations)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"13.1.2" from @angular/[email protected]
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~13.1.0" from the root project
npm ERR!   peer @angular/common@"^13.1.0" from @mintplayer/[email protected]
npm ERR!   node_modules/@mintplayer/ng-animations
npm ERR!     @mintplayer/ng-animations@"*" 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.

I'm on the latest version of angular:

> ng version

Angular CLI: 13.1.3
Node: 14.18.2
Package Manager: npm 8.3.0
OS: win32 x64

Angular: 13.1.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.3
@angular-devkit/build-angular   13.1.3
@angular-devkit/core            13.1.3
@angular-devkit/schematics      13.1.3
@angular/cli                    13.1.3
@schematics/angular             13.1.3
rxjs                            7.4.0
typescript                      4.5.4

> node -v
v14.18.2

> npm -v
8.3.0

I had a similar problem some time ago, but that was when I was upgrading my application from angular 11 to 13, and I was able to solve it by checking the versions of the specific package npm was complaining about. But now all versions are the same (13.x.x or 13.1.x).

Everything is targetting angular 13.1, so where does this error come from? Any help is highly appreciated.

like image 419
Pieterjan Avatar asked Oct 23 '25 02:10

Pieterjan


2 Answers

I was trying to install @angular/service-worker, however it showed me a similar issue, what I did was:

  • Delete the node_modules package
  • Then run npm update instead of npm install

The version of my package @angular/service-worker was already on package.json before running the command npm update.

like image 116
Victor Say Avatar answered Oct 25 '25 17:10

Victor Say


your global verson is the latest but not the project version. run npx @angular/cli@13 update @angular/core@13 @angular/cli@13 inside the project and the install the dependency again

another option is to install the library it with --force flag

like image 37
Zerotwelve Avatar answered Oct 25 '25 17:10

Zerotwelve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!