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

M1芯片Mac上Angular项目npm安装失败原因排查

Angular项目迁移后npm install失败原因分析

问题背景

旧Mac硬件故障更换为M1芯片MacBook Air后,迁移Angular项目执行npm install时抛出ERESOLVE错误。

关键信息

项目package.json核心依赖

{
  "dependencies": {
    "@agm/core": "1.1.0",
    "@angular/common": "13.0.1",
    "@angular/material": "13.0.1",
    // 其他依赖省略
  },
  "devDependencies": {
    "@angular/cli": "13.0.2",
    "typescript": "4.4.4"
    // 其他依赖省略
  }
}

npm install错误日志核心片段

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @agm/core@1.1.0
npm ERR! Found: @angular/common@13.0.1
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^6.0.0 || ^7.0.0 || ^8.0.0" from @agm/core@1.1.0
npm ERR! Conflicting peer dependency: @angular/common@8.2.14

环境信息

  • 全局Angular CLI: 13.3.11
  • 项目内npm版本: 9.8.1
  • 项目内Node版本: 16.20.2

错误原因

  1. 核心依赖冲突:
    @agm/core@1.1.0的peer依赖声明仅支持Angular 6/7/8版本,但项目使用的是Angular 13.0.1,两者版本范围完全不兼容。npm 7及以上版本默认启用严格的peer依赖校验机制,因此检测到冲突后直接终止安装流程。

  2. 触发因素:
    迁移到新设备后使用的npm 9.8.1严格执行peer依赖校验,而旧设备上可能使用的是npm 6或更早版本,这类版本会自动忽略peer依赖冲突,所以之前没有暴露这个问题。该错误与M1芯片架构无关,本质是依赖版本不匹配。

解决建议

  • 优先方案:替换@agm/core:
    @agm/core已停止维护,官方推荐使用@angular/google-maps(Angular官方Google Maps集成包),该包支持Angular 13及以上版本,完全适配项目当前环境。

  • 临时绕过方案:
    执行npm install --legacy-peer-deps强制忽略peer依赖冲突完成安装,但可能导致运行时出现未知bug,仅作为临时测试使用。

  • 不推荐方案:降级Angular:
    将项目Angular版本降级到8.x,虽然能匹配@agm/core的依赖要求,但会导致其他依赖(如@angular/material@13.0.1)也需要同步降级,改动范围大,维护成本极高。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 04:05:07