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

如何降级@angular/google-maps版本解决Angular依赖冲突?

Angular依赖冲突问题求助

我的项目当前使用@angular/google-maps版本为15.0.2,但项目依赖的Angular版本是14.2.6,安装其他库时出现依赖冲突,因此需要降级@angular/google-maps版本。尝试卸载@angular/google-maps@15.2.9以安装旧版本时,遇到依赖冲突问题,报错信息如下:

PS C:\Project> npm uninstall @angular/google-maps@15.2.9
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @angular/google-maps@15.2.9
npm ERR! Found: @angular/common@14.3.0
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@"^14.0.0 || ^15.0.0" from @angular/cdk@14.2.7
npm ERR!   node_modules/@angular/cdk
npm ERR!     peer @angular/cdk@"14.2.7" from @angular/material@14.2.7
npm ERR!     node_modules/@angular/material
npm ERR!       peer @angular/material@"14.2.7" from @angular/material-moment-adapter@14.2.7
npm ERR!       node_modules/@angular/material-moment-adapter
npm ERR!         @angular/material-moment-adapter@"^14.2.5" from the root project
npm ERR!       1 more (the root project)
npm ERR!     @angular/cdk@"^14.2.5" from the root project
npm ERR!   peer @angular/common@"^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0" from @angular/fire@7.5.0
npm ERR!   node_modules/@angular/fire
npm ERR!     @angular/fire@"^7.4.0" from the root project
npm ERR!   6 more (@angular/forms, @angular/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^15.0.0 || ^16.0.0" from @angular/google-maps@15.2.9
npm ERR! node_modules/@angular/google-maps
npm ERR!   @angular/google-maps@"^15.0.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/common@16.2.12
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@"^15.0.0 || ^16.0.0" from @angular/google-maps@15.2.9
npm ERR!   node_modules/@angular/google-maps
npm ERR!     @angular/google-maps@"^15.0.2" 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!
npm ERR! For a full report see:
npm ERR! C:\Users\Marti\AppData\Local\npm-cache\_logs\2024-04-22T19_10_48_543Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in: C:\Users\Marti\AppData\Local\npm-cache\_logs\2024-04-22T19_10_48_543Z-debug-0.log

解决建议

  • 直接安装适配Angular 14的版本:无需单独卸载现有版本,直接指定安装与Angular 14兼容的@angular/google-maps 14.x版本,npm会自动替换并处理依赖:

    npm install @angular/google-maps@14 --save
    
  • 清理缓存后重装依赖:如果上述命令执行失败,尝试以下步骤:

    1. 清理npm缓存:
      npm cache clean --force
      
    2. 删除项目根目录下的node_modules文件夹和package-lock.json文件
    3. 重新安装所有依赖:
      npm install
      
  • 临时绕过peer依赖检查:若前两种方法都无效,可使用--legacy-peer-deps参数强制安装,但需注意这可能引发潜在兼容性问题:

    npm install @angular/google-maps@14 --save --legacy-peer-deps
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 12:34:51