You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法安装@ng-bootstrap/ng-bootstrap?依赖冲突问题求助

解决Angular安装@ng-bootstrap/ng-bootstrap时的ERESOLVE依赖冲突

问题核心

你安装的@ng-bootstrap/ng-bootstrap@13.0.0对@angular/forms有依赖要求,而满足该要求的@angular/forms@14.2.6需要配套@angular/core@14.2.6,但你的项目当前使用的@angular/core是14.2.2,版本不匹配导致npm无法自动解析依赖,抛出ERESOLVE错误。

可行解决方案

1. 统一升级Angular核心包到14.2.6

你的Angular核心包版本都是^14.2.0的范围,直接执行以下命令,把所有Angular核心依赖统一升级到14.2.6:

npm install @angular/core@14.2.6 @angular/animations@14.2.6 @angular/common@14.2.6 @angular/compiler@14.2.6 @angular/forms@14.2.6 @angular/platform-browser@14.2.6 @angular/platform-browser-dynamic@14.2.6 @angular/router@14.2.6 @angular/compiler-cli@14.2.6

这样能让所有Angular核心包版本一致,完美匹配ng-bootstrap的依赖要求。

2. 用兼容参数跳过peer依赖检查

如果暂时不想升级Angular,可以在安装ng-bootstrap时添加--legacy-peer-deps参数,让npm忽略严格的peer依赖校验:

npm install @ng-bootstrap/ng-bootstrap@13.0.0 --legacy-peer-deps

注意:这种方式可能带来潜在兼容性问题,建议仅作为临时方案,后续尽量统一版本。

3. 手动修改package.json统一版本

直接修改package.json中所有Angular相关依赖的版本为14.2.6,确保版本完全一致:
修改dependencies中的相关项:

"@angular/animations": "14.2.6",
"@angular/cdk": "14.2.6",
"@angular/common": "14.2.6",
"@angular/compiler": "14.2.6",
"@angular/core": "14.2.6",
"@angular/forms": "14.2.6",
"@angular/material": "14.2.6",
"@angular/platform-browser": "14.2.6",
"@angular/platform-browser-dynamic": "14.2.6",
"@angular/router": "14.2.6",

修改devDependencies中的相关项:

"@angular/compiler-cli": "14.2.6"

修改完成后执行npm install即可。

总结

优先选择方案1或3,通过统一Angular核心包版本从根本上解决依赖冲突;方案2仅作为临时应急手段,后续需做好兼容性测试。

内容的提问来源于stack exchange,提问作者Isaac Lyne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 15:25:14