【问题标题】:Can't execute npm install无法执行 npm install
【发布时间】:2022-02-08 00:25:32
【问题描述】:

当我执行 npm install 时,会显示此错误。对此有何建议?

PS C:\Users\alex\Downloads\team> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: frontend@0.0.0
npm ERR! Found: @angular/compiler@13.1.3
npm ERR! node_modules/@angular/compiler
npm ERR! @angular/compiler@"~13.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"13.0.3" from @angular/compiler-cli@13.0.3
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"~13.0.0" from the root project
npm ERR! peer @angular/compiler-cli@"^13.0.0" from @angular-devkit/build-angular@13.2.2
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"^13.2.0" 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! See C:\Users\ for a full report.



npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\

这是 Package.json 文件:

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "^13.1.0",
    "@angular/cdk": "^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",
    "@types/jquery": "^3.5.13",
    "bootstrap": "^5.1.3",
    "bootstrap4-toggle": "^3.6.1",
    "colors": "^1.4.0",
    "jquery": "^3.6.0",
    "rxjs": "~7.4.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^13.2.0",
    "@angular/cli": "~13.0.4",
    "@angular/compiler-cli": "~13.0.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.0.3",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.4.3"
  }
}

【问题讨论】:

  • 删除package-lock.json文件和node_modules文件夹,然后执行npm install
  • 做了但仍然有同样的错误
  • 如果您也发布 package.json 的全部内容,这可能会有所帮助
  • 您好,我已将 package.json 添加到 OP
  • 似乎与 "@angular/compiler": "~13.1.0","@angular/compiler-cli": "~13.0.0", 之类的软件包有冲突,您可能应该决定是否希望角度内容全部为 13.1 或 13.0

标签: npm


【解决方案1】:

ERESOLVEnpm@7npm@8 的问题很常见,因为它们比 npm@6 对对等依赖项更严格。通常,最简单的解决方法是将--legacy-peer-deps 标志传递给npm(例如npm i --legacy-peer-deps),或者使用npm@6

“正确”的解决方案是找出您的哪些依赖项需要在package.json 中更新以避免对等依赖项冲突,但这有时对于未维护的依赖项是不可能的。在这种情况下,解决方案是找到或创建其他东西来摆脱未维护的依赖关系。

然而,十分之九,有人只想安装这些东西并希望它能正常工作,在这种情况下--legacy-peer-deps 会这样做。只需确保您具有良好的测试覆盖率,因为您使用的对等依赖版本与包指定的版本不同,因此某处可能无法正常工作。

要查看问题是否会影响您的生产应用,请发送npm install --production。如果它没有给你一个ERESOLVE 错误,那么问题就出在你的开发依赖中,这通常不是一个问题。

【讨论】:

    猜你喜欢
    • 2020-02-29
    • 2014-12-14
    • 2019-11-28
    • 2017-04-13
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 2018-04-12
    • 1970-01-01
    相关资源
    最近更新 更多