Npm安装失败(无法解决依赖项)

28

当我尝试执行npm install时,出现以下情况:

当我尝试执行npm install时,出现以下情况:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: foliosure@1.0.1
npm ERR! Found: zone.js@0.8.29
npm ERR! node_modules/zone.js
npm ERR!   zone.js@"~0.8.26" from the root project
npm ERR!   peer zone.js@"~0.8.26" from @angular/core@7.2.16
npm ERR!   node_modules/@angular/core
npm ERR!     @angular/core@"~7.2.0" from the root project
npm ERR!     peer @angular/core@"^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0" from primeng_latest@11.2.3
npm ERR!     node_modules/primeng_latest
npm ERR!       primeng_latest@"npm:primeng@^11.2.0" from the root project
npm ERR!     3 more (@angular/common, @angular/forms, @angular/platform-browser)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer zone.js@"^0.10.2" from primeng_latest@11.2.3
npm ERR! node_modules/primeng_latest
npm ERR!   primeng_latest@"npm:primeng@^11.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

这是我的package.json依赖文件:

  "dependencies": 
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/http": "^7.2.4",
    "@angular/material": "^7.3.7",
    "@angular/router": "~7.2.0",
    "@types/d3": "^5.7.2",
    "bootstrap": "^4.4.1",
    "codemirror": "^5.58.2",
    "file-saver": "^2.0.0",
    "font-awesome": "^4.7.0",
    "highcharts": "^9.0.0",
    "material-design-icons": "^3.0.1",
    "moment": "^2.24.0",
    "ngx-spinner": "^7.2.0",
    "ngx-toastr": "^9.2.0",
    "primeicons": "^1.0.0",
    "primeng": "^7.0.5",
    "primeng_latest": "npm:primeng@^11.2.0",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"

我尝试了降低版本,但仍然出现错误。我也尝试在谷歌上搜索解决方案,但没有找到正确的解决方案,希望能得到任何帮助,谢谢。


"devDependencies": "@angular-builders/custom-webpack": "^7.4.3", "@angular-builders/dev-server": "7.3.1", "@angular-devkit/build-angular": "^0.13.2", "@angular-devkit/build-ng-packagr": "0.13.0", "@angular-devkit/core": "^11.0.1", "@angular/compiler-cli": "7.2.0", "ng-packagr": "^4.2.0", "primeng": "^6.1.7", "ts-node": "7.0.0", "tsickle": ">=0.34.0", "tslib": "^1.9.0", "tslint": "5.11.0", "typescript": "3.2.2", "webpack-dev-server": "^3.11.2" - Ananya Rao
1
你有一个 package-lock.json 文件,请尝试运行以下命令:npm ci。如果仍然失败,请删除 package-lock.json 和 node_modules 文件夹,然后尝试运行 npm i 命令。 - Rohit Dalal
谢谢Rohit Dalal,但是它没有起作用,仍然出现相同的错误。 - Ananya Rao
3个回答

85

看起来这可能是与对等依赖项有关的问题,请尝试使用 npm install --legacy-peer-deps


1
浪费了我整整一天的时间,最终找到了这个解决方案,成功解决了我的问题。 - Qwerty
谢谢!已解决npm install @formkit/auto-animate安装问题。 - Ayush
我执行了这个程序,从1个错误增加到了45个错误。 - Markus
@Markus,请告诉我们其他人你是如何解决这些问题的,谢谢。 - Nathan majicvr.com
1
如果我没记错的话,这是一个删除节点模块文件夹并确保 package.json 中的所有版本与依赖项所期望的版本相匹配的问题。 - Markus

33

您可以通过运行npm install --legacy-peer-deps来跳过对同级依赖冲突的检查,或者您可以设置npm config set legacy-peer-deps true,然后再次运行npm install


2
如果您想在自己的计算机上运行朋友的angular代码,请按照以下步骤操作。
步骤1:可能是由于您的node版本和朋友的node版本以及npm版本不匹配导致的。 C://projectFolder> node --version 然后 C://projectFolder> npm -v
步骤2:如果版本不匹配,则卸载您计算机上的node,然后重新启动,安装朋友的node版本。
步骤3: 运行下面的示例代码。
1.
npm install npm@[version]

在我的电脑上

npm install -g npm@6.2.0
  1. 现在在项目文件夹中运行npm install命令

    npm install

  2. 现在运行npm start或ng serve命令,以确保正常工作


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接