npm install --force和npm install --legacy-peer-deps有什么区别?

7

我正在尝试使用npm install安装项目的node_modules。但是失败了。

错误日志

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: my-first-app@0.0.0
npm ERR! Found: @angular/compiler@11.0.9
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/compiler-cli@11.0.9
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/build-angular@0.1100.7
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/localize@11.1.2
npm ERR! node_modules/@angular/localize
npm ERR!   peerOptional @angular/localize@"^11.0.0" from @angular-devkit/build-angular@0.1100.7
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 --forcenpm install --legacy-peer-deps之间的基本区别。

另外,如果--force--legacy-peer-deeps的性能更好,哪一个更可取?

任何建议/指针都非常感谢。谢谢!


1
这个回答解决了你的问题吗?npm:何时使用`--force`和`--legacy-peer-deps` - Joe
1
谢谢@Joe!你建议的问题与我的类似,但是我在阅读答案后并不是很清楚这个概念。如果有人能帮助我用通俗易懂的术语理解基本区别,那将非常有帮助。 - Amit kumar
我已经更新了问题,以便更清楚地表达我所寻找的内容。 - Amit kumar
1个回答

0

两者之间的区别如下:

--legacy-peer-deps:在安装时忽略所有peerDependencies,类似于npm版本4到版本6的风格。

--strict-peer-deps: 当遇到任何冲突的peerDependencies时,会失败并中止安装过程。默认情况下,npm仅会因根项目的直接依赖项引起的peerDependencies冲突而崩溃。

--forces : 即使磁盘上存在本地副本,也将强制npm获取远程资源。


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