如何修复 ERESOLVE 无法解析 npm install 的依赖关系树

Kav*_*dya 14 npm typescript package.json npm-install angular

我目前对角度和自学还比较陌生。以前一切都工作正常,直到我决定将很多新东西导入到我的项目中。简而言之,我发现我可以删除 node_modules 并运行 npm install。删除它后,当我运行 npm install 时出现以下错误。

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: appla-katta@0.0.0
npm ERR! Found: @angular/common@12.2.16
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"~12.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^14.0.0 || ^15.0.0" from @angular/cdk@14.0.2
npm ERR! node_modules/@angular/cdk
npm ERR!   @angular/cdk@"14.0.2" 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\kavis\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\kavis\AppData\Local\npm-cache\_logs\2022-06-20T10_45_13_413Z-debug-0.log
Run Code Online (Sandbox Code Playgroud)

我不确定该错误意味着什么,但我认为我有不同的版本,因为我猜存在依赖错误。我尝试跑步npm install @angular/cdk@latestng update @angular/common但没有结果。我什至找到了更多解决方案,例如删除节点模块,但package_lock.jsonnpm install 不起作用。

我尝试强制 npm install 但由于其他原因我的项目没有运行,所以我希望解决这里的错误本身

谢谢

以下是我的 package.json 内容

{
  "name": "appla-katta",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "node build && firebase deploy",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  
  "private": true,
  "dependencies": {
    "@angular/animations": "~12.2.0",
    "@angular/cdk": "^13.3.2",
    "@angular/common": "~12.2.0",
    "@angular/compiler": "~12.2.0",
    "@angular/core": "~12.2.0",
    "@angular/fire": "github:angular/fire",
    "@angular/flex-layout": "^13.0.0-beta.38",
    "@angular/forms": "~12.2.0",
    "@angular/material": "^13.3.2",
    "@angular/platform-browser": "~12.2.0",
    "@angular/platform-browser-dynamic": "~12.2.0",
    "@angular/router": "~12.2.0",
    "@auth0/auth0-angular": "^1.9.0",
    "@fortawesome/fontawesome-free": "^6.1.1",
    "angularfire2": "^5.4.2",
    "bootstrap": "^5.1.3",
    "cors": "^2.8.5",
    "firebase": "^7.24.0",
    "json-server": "^0.17.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~12.2.7",
    "@angular/cli": "~12.2.7",
    "@angular/compiler-cli": "~12.2.0",
    "@types/jasmine": "~3.8.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~3.8.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.3.5"
  }
}
Run Code Online (Sandbox Code Playgroud)

另外,我还有 package-lock.json,现在已将其删除。

Mah*_*rei 30

删除node_modulespackage-lock.json.

然后试试这个:

npm install --legacy-peer-deps
Run Code Online (Sandbox Code Playgroud)

  • 与应用程序使用的版本 (13) 相比,我的 PC 上有较新版本的 Angular (14),并且效果非常好。 (2认同)