How do you read npm audit ERESOLVE error?

Viewed 581

I often receive error ERESOLVE similar to below. How do you read it?

>npm audit fix
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: myapp@0.0.0
npm ERR! Found: @angular/compiler@12.1.0
npm ERR! node_modules/@angular/compiler
npm ERR!   @angular/compiler@"12.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"12.1.1" from @angular/compiler-cli@12.1.1
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   dev @angular/compiler-cli@"^12.1.0" from the root project
npm ERR!   peer @angular/compiler-cli@"^12.0.0 || ^12.1.0-next" from @angular-devkit/build-angular@12.1.0
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"12.1.0" from the root project

And how do you read it - Which package depends on which? Which end of the tree I have control of? Top or bottom?

Did I add @angular-devkit/build-angular into my app and it needs but cant find angular/compiler ? or is it the other way around?

2 Answers

I can be wrong but this is what I read:

Which package depends on which?

Your app directly depends on:

  • @angular/compiler@"12.1.0"
  • @angular/compiler-cli@"^12.1.0"
  • @angular-devkit/build-angular@"12.1.0"

Your app transitively depends on:

  • @angular/compiler@"12.1.1" from @angular/compiler-cli@12.1.1 <- which is the actual @angular/compiler-cli version installed in your node_modules.
  • @angular/compiler-cli@"^12.0.0 || ^12.1.0-next" from @angular-devkit/build-angular@12.1.0 <- which is the actual @angular-devkit/build-angular version installed in your node_modules.

So what I read is that there is a conflict because your app directly depends on @angular/compiler@"12.1.0" and transitively on @angular/compiler@"12.1.1" (from @angular/compiler-cli@12.1.1) You can probably fix this by adding what it looks like a missing caret, ie @angular/compiler@"^12.1.0".

Unrelated ^, I had a similar problem but all versions where compatible. I deleted package-lock.json and node_modules and installed them again and it worked fine.

I've fixed it with following commands:

  1. rm package-lock.json
  2. rm -rf node_modules
  3. yarn install
  4. npm i
Related