user1012506
user1012506

Reputation: 2118

Error when installing material-moment-adapter package in angular

I try run this command in terminal:

npm i moment @angular/material-moment-adapter.

I got errors:

 npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
 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@"^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0" from the root project 
 npm ERR! npm ERR! Could not resolve dependency: 
 npm ERR! peer @angular/core@"^14.0.0 || ^15.0.0" from @angular/[email protected] 
 npm ERR! node_modules/@angular/material-moment-adapter 
 npm ERR!   @angular/material-moment-adapter@"*" 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. 
 npm ERR! 
 npm ERR! See C:\Users\xxx\AppData\Local\npm-cache\eresolve-report.txt for a full report.
 npm ERR! A complete log of this run can be found in: npm ERR!     C:\Users\xxxx\AppData\Local\npm-cache\_logs\2022-08-11T06_40_07_646Z-debug-0.log

I tried run npm install and npm i moment and not working.

(The others "duplicate questions" are not the same situation)

This is package json:

{ "name": "certificate-blindess", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "format": "prettier --write "src//*.{ts,html,scss,json}" "!src//migrate/**/." }, "private": true, "dependencies": { "@angular/animations": "~10.1.6", "@angular/cdk": "^10.2.7", "@angular/common": "~10.1.6", "@angular/compiler": "~10.1.6", "@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0", "@angular/forms": "~10.1.6", "@angular/material": "^10.2.7", "@angular/platform-browser": "~10.1.6", "@angular/platform-browser-dynamic": "~10.1.6", "@angular/router": "~10.1.6", "@binssoft/ngx-captcha": "^1.0.0", "@types/lodash": "^4.14.162", "cors": "^2.8.5", "file-saver": "^2.0.5", "flatted": "^3.2.4", "lodash": "^4.17.20", "mat-file-upload": "^11.1.2", "ng-recaptcha": "^8.0.1", "ngx-bootstrap": "^6.2.0", "prettier": "^2.1.2", "rxjs": "~6.6.0", "tslib": "^2.0.0", "zone.js": "~0.10.2" }, "devDependencies": { "@angular-devkit/build-angular": "~0.1001.7", "@angular/cli": "^10.2.3", "@angular/compiler-cli": "~10.1.6", "@types/file-saver": "^2.0.1", "@types/jasmine": "~3.5.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "codelyzer": "^6.0.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", "protractor": "~7.0.0", "ts-node": "~8.3.0", "tslint": "~6.1.0", "typescript": "~4.0.2" }, "peerDependencies": { "@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0" } }

.

Upvotes: 0

Views: 2835

Answers (1)

Pascal
Pascal

Reputation: 418

Why you get the error:

You are trying to install a recent version (14.1.1) of @angular/material-moment-adapter to an Angular project which is on major version 10. This causes dependency conflicts because the different Angular packages depend on each other and mostly require the same major version.

You can read this from this error message:

peer @angular/core@"^14.0.0 || ^15.0.0" from @angular/[email protected]

It says, that the @angular/material-moment-adapter wants @angular/core in version 14.x.x or 15.x.x.

What you can do:

In your case, I see two possible ways to go:

  1. Install an older version of the @angular/material-moment-adapter by running:

npm i @angular/material-moment-adapter@10 moment

  1. Upgrade to the major version 14 of all Angular packages (step by step). See their update guide for help.

Side notes

  1. Your @angular/core dependency in the dependencies section of the package.json looks strange:

"@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",

With this setup, you basically allow any version between 6.0.0 and the latest 10ish version. But any other version than 10.x.x would cause conflicts with other dependencies. Therefore, I would recommend to use a different version specification here like the one specified for @angular/common and so on (= ~10.1.6).

  1. You also got @angular/core as peer dependency. This means, that anyone installing your package requires @angular/core being installed in any of the versions listed here:

"@angular/core": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0"

If your workspace does not contain a library which should be consumed by other libraries or apps, then you may probably want to delete this peerDependencies entry.

Upvotes: 1

Related Questions