Angular 13安装依赖时Protractor对等依赖冲突问题
Angular 13安装ngx-bootstrap时的ERESOLVE依赖冲突解决
第一个冲突:protractor版本不匹配
错误信息
npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @angular-devkit/build-angular@13.2.0 npm ERR! Found: protractor@6.0.0 npm ERR! node_modules/protractor npm ERR! dev protractor@"^6.0.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peerOptional protractor@"^7.0.0" from @angular-devkit/build-angular@13.2.0 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! Conflicting peer dependency: protractor@7.0.0 npm ERR! node_modules/protractor npm ERR! peerOptional protractor@"^7.0.0" from @angular-devkit/build-angular@13.2.0 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! npm ERR! See C:\Users\user\AppData\Local\npm-cache\eresolve-report.txt for a full report.
原因
项目中安装的protractor@6.0.0和@angular-devkit/build-angular@13.2.0要求的可选peer依赖protractor@^7.0.0版本不兼容,导致npm依赖解析失败。
解决方法
升级protractor到7.x版本:
npm install protractor@^7.0.0 --save-dev
第二个冲突:@ng-bootstrap/ng-bootstrap版本与Angular 13不兼容
错误信息
npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @ng-bootstrap/ng-bootstrap@9.1.1 npm ERR! Found: @angular/common@13.1.1 npm ERR! node_modules/@angular/common npm ERR! peer @angular/common@">=6.1.0" from @angular-slider/ngx-slider@2.0.3 npm ERR! node_modules/@angular-slider/ngx-slider npm ERR! @angular-slider/ngx-slider@"^2.0.3" from the root project npm ERR! peer @angular/common@"^13.0.0 || ^14.0.0-0" from @angular/cdk@13.1.1 npm ERR! node_modules/@angular/cdk npm ERR! peer @angular/cdk@"13.1.1" from @angular/material@13.1.1 npm ERR! node_modules/@angular/material npm ERR! @angular/material@"^13.1.1" from the root project npm ERR! peer @angular/cdk@">=12.0.0" from @swimlane/ngx-charts@20.0.1 npm ERR! node_modules/@swimlane/ngx-charts npm ERR! @swimlane/ngx-charts@"^20.0.1" from the root project npm ERR! 1 more (the root project) npm ERR! 13 more (@angular/forms, @angular/material, ...) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @angular/common@"^11.0.0" from @ng-bootstrap/ng-bootstrap@9.1.1 npm ERR! node_modules/@ng-bootstrap/ng-bootstrap npm ERR! @ng-bootstrap/ng-bootstrap@"^9.1.1" from the root project npm ERR! npm ERR! Conflicting peer dependency: @angular/common@11.2.14 npm ERR! node_modules/@angular/common npm ERR! peer @angular/common@"^11.0.0" from @ng-bootstrap/ng-bootstrap@9.1.1 npm ERR! node_modules/@ng-bootstrap/ng-bootstrap npm ERR! @ng-bootstrap/ng-bootstrap@"^9.1.1" 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\user\AppData\Local\npm-cache\eresolve-report.txt for a full report.
原因
@ng-bootstrap/ng-bootstrap@9.1.1是为Angular 11设计的,要求peer依赖@angular/common@^11.0.0,但项目使用的是Angular 13,版本不匹配导致冲突。@ng-bootstrap/ng-bootstrap的版本和Angular版本严格对应:v9→Angular11,v10→Angular12,v11→Angular13。
解决方法
升级@ng-bootstrap/ng-bootstrap到适配Angular13的v11.x版本:
npm install @ng-bootstrap/ng-bootstrap@^11.0.0 --save
最终安装ngx-bootstrap
完成上述两个依赖修复后,执行以下命令安装ngx-bootstrap:
ng add ngx-bootstrap
内容的提问来源于stack exchange,提问作者Software Developer
相关产品推荐
相关产品推荐

