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

Angular 18.1.3无法安装ng-bootstrap 17.0.0问题求助

解决Angular 18.1.3安装ng-bootstrap 17.0.0的依赖冲突问题

问题核心

执行ng add @ng-bootstrap/ng-bootstrap时触发npm ERESOLVE依赖解析错误,原因是:

  • 项目当前使用@angular/core@18.1.3
  • ng-bootstrap 17.0.0的peer依赖要求@angular/forms@^18.0.0,但npm解析时会尝试拉取@angular/forms@18.2.0,而该版本强制依赖@angular/core@18.2.0,导致版本不匹配冲突。

解决方案

方案1:升级Angular项目到18.2.x版本(推荐)

确保Angular核心包版本统一,彻底解决依赖冲突:

  1. 执行Angular升级命令:
ng update @angular/core@18.2 @angular/cli@18.2
  1. 升级完成后安装ng-bootstrap:
ng add @ng-bootstrap/ng-bootstrap

方案2:使用--legacy-peer-deps参数跳过依赖检查

若暂时不想升级Angular,可通过该参数强制安装(注意:可能存在潜在兼容性风险):

ng add @ng-bootstrap/ng-bootstrap --legacy-peer-deps

或直接用npm命令安装:

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

方案3:手动锁定@angular/forms版本

  1. 打开项目根目录的package.json,将@angular/forms的版本设置为18.1.3(与@angular/core版本保持一致)
  2. 执行依赖重装:
npm install
  1. 再次执行ng-bootstrap安装命令:
ng add @ng-bootstrap/ng-bootstrap

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 14:24:52