我正在尝试使用
npm install
为项目安装node_modules。但失败了。
错误日志:
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/compiler
npm ERR! @angular/compiler@"~11.0.0" from the root project
npm ERR! peer @angular/compiler@"11.0.9" from @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"~11.0.0" from the root project
npm ERR! peer @angular/compiler-cli@"^11.0.0" from @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1100.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"11.1.2" from @angular/[email protected]
npm ERR! node_modules/@angular/localize
npm ERR! peerOptional @angular/localize@"^11.0.0" from @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1100.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!
npm ERR! See /Users/amit/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/amit/.npm/_logs/2021-02-04T17_58_24_981Z-debug.log
日志建议使用
npm install --force
或 npm install --legacy-peer-deps
我想了解
npm install --force
和 npm install --legacy-peer-deps
之间的基本区别。
另外,如果
--force
的性能优于 --legacy-peer-deeps
或反之亦然,那么更优选使用哪一个?
任何建议/指示都非常值得赞赏。谢谢!
两者的区别如下
--legacy-peer-deps
:安装时忽略所有对等依赖项,采用 npm 版本 4 到版本 6 的风格
--strict-peer-deps:
遇到任何冲突的对等依赖项时会失败并中止安装过程。默认情况下,npm 只会因根项目的直接依赖项引起的 PeerDependency 冲突而崩溃。
--forces :
将强制 npm 获取远程资源,即使磁盘上存在本地副本也是如此。