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

Angular 15(ngx-admin)项目因依赖冲突无法安装依赖

Angular 15项目npm install依赖解析错误解决方案

最近克隆了一个Angular 15版本的项目,执行npm install安装依赖时遇到以下错误:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: ngx-admin@11.0.0
npm error Found: @angular/common@15.2.10
npm error node_modules/@angular/common
npm error   @angular/common@"^15.2.10" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @angular/common@"^12.0.0 || ^13.0.0-0" from @angular/google-maps@12.2.13
npm error node_modules/@angular/google-maps
npm error   @angular/google-maps@"^12.2.13" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error C:\Users\ANAS\AppData\Local\npm-cache\_logs\2024-11-04T20_28_26_776Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\ANAS\AppData\Local\npm-cache\_logs\2024-11-04T20_28_26_776Z-debug-0.log

问题原因

项目依赖的@angular/google-maps@12.2.13仅兼容Angular 12或13版本,但当前项目使用的是Angular 15.2.10,两者的peer依赖版本不匹配,导致依赖解析失败。


解决方案

临时快速解决(不推荐长期使用)

执行带参数的安装命令,跳过依赖冲突检查:

npm install --legacy-peer-deps

或

npm install --force

注:--legacy-peer-deps采用npm v6的依赖解析规则,忽略peer依赖冲突;--force会强制安装,可能引发潜在兼容性问题。

彻底解决(推荐)

更新@angular/google-maps到兼容Angular 15的版本:

  1. 安装与Angular核心版本匹配的@angular/google-maps(Angular官方库版本与核心版本保持一致):
    npm install @angular/google-maps@^15.2.10 --save
    
  2. 重新执行依赖安装:
    npm install
    
  3. 若项目依赖的ngx-admin@11.0.0本身限制了@angular/google-maps版本,需确认ngx-admin 11是否支持Angular 15。若不支持,需升级ngx-admin到兼容Angular 15的版本,或调整项目Angular版本至ngx-admin支持的范围。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 15:46:10