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

安装angular-highcharts遇依赖树解析错误:@angular/common版本冲突

Angular安装angular-highcharts的依赖冲突解决办法

问题重现

执行安装命令:

PS C:\Users\YUNUS\Desktop\newProject\gos-panel\src\app\shared> npm i angular-highcharts highcharts

触发以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE 无法解析依赖树
npm ERR!
npm ERR! 解析时:gos-panel@0.0.0
npm ERR! 已找到:@angular/common@14.1.0
npm ERR! node_modules/@angular/common
npm ERR!
npm ERR! 无法解析依赖:
npm ERR! angular-highcharts@14.1.5 需要 peer @angular/common@"^13.0.0"
npm ERR! node_modules/angular-highcharts
npm ERR! angular-highcharts@"*" 来自根项目
npm ERR!
npm ERR! 修复上游依赖冲突,或使用 --force 或 --legacy-peer-deps 参数重试
npm ERR! 以接受不正确(可能损坏)的依赖解析。
npm ERR!
npm ERR! 完整报告请查看:C:\Users\YUNUS\AppData\Local\npm-cache\eresolve-report.txt
npm ERR!
npm ERR! 本次运行的完整日志位于:
npm ERR! C:\Users\YUNUS\AppData\Local\npm-cache_logs\2022-07-25T13_43_51_090Z-debug-0.log

冲突原因

你的项目使用Angular 14.1.0,但默认安装的angular-highcharts@14.1.5仅兼容Angular 13版本(依赖要求@angular/common@^13.0.0),版本不匹配导致依赖树解析失败。

解决办法

1. 安装适配Angular 14的版本

angular-highcharts的v15.x版本专门适配Angular 14,直接安装对应版本即可:

npm i angular-highcharts@^15.0.0 highcharts

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

如果暂时不想调整版本,可以用--legacy-peer-deps参数强制安装(采用旧版npm的peer依赖解析逻辑,忽略版本冲突):

npm i angular-highcharts highcharts --legacy-peer-deps

不优先推荐--force参数,它会直接覆盖现有依赖,更容易引发其他问题

3. 降级Angular到13.x版本

如果项目允许,可将Angular降级到13.x版本,这样就能直接安装angular-highcharts@14.1.5,但降级可能影响其他依赖,操作前建议备份项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 22:39:19