#understand package installation errors

7 messages · Page 1 of 1 (latest)

edgy sapphire
#

package.json

{
  "dependencies": {
...
    "@angular/material": "~20.0.5",
    "@angular/material-moment-adapter": "^20.0.5",
ng add @angular-eslint/schematics -f
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: @angular/material-moment-adapter@20.1.0
npm error Found: @angular/material@20.0.6
npm error node_modules/@angular/material
npm error   @angular/material@"~20.0.5" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @angular/material@"20.1.0" from @angular/material-moment-adapter@20.1.0
npm error node_modules/@angular/material-moment-adapter
npm error   @angular/material-moment-adapter@"^20.0.5" from the root project
npm error
npm error Conflicting peer dependency: @angular/material@20.1.0
npm error node_modules/@angular/material
npm error   peer @angular/material@"20.1.0" from @angular/material-moment-adapter@20.1.0
npm error   node_modules/@angular/material-moment-adapter
npm error     @angular/material-moment-adapter@"^20.0.5" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
  • I put "-f", why does it refuse to install it?
  • what is the relationship between eslint and material?
  • can you help me understand what these errors mean? and how to resolve ?
proven basalt
#

You're mixing ^ (use latest minor version) and ~ (use latest patch version) for things that should have the same version number. So one is updated to 20.1.0 but the other can't, thus causing dependency conflicts.

edgy sapphire
#

ok but I didn't ask to install version 20.1.0 of moment ..
I want to install eslint
That’s what I don’t understand?

proven basalt
#

I don't know npm and the ng add command well enough to know precisely when they decide to resolve new dependencies, but they do. And since you used ^ and ~ rather than fixed versions, you accepted to install newer versions.

edgy sapphire
#

OK thanks
so it is recommended to put ~ everywhere in package.json instead of ^
so that it installs corrected versions?

#
  • so I delete the node_modules folder
  • replace ^ with ~
  • npm i
proven basalt
#

No. It's recommended to be consistent and logical.
If you want, for a group of dependencies that must always have the same version number (like material and material-moment-adapter) to automatically upgrade to the latest minor version, then use ^, consistently.
If you want to automatically upgrade to the latest patch version, then use ~, consistently.
If you want to avoid automatic upgrades and be in control of when and what to upgrade, use fixed version numbers.