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

Angular应用Linux部署npm依赖冲突问题求助

问题

为客户部署Angular应用时,Windows开发环境可正常运行,但在Linux环境使用NodeJS 19执行npm install时遭遇依赖解析错误。已尝试--force和--legacy-peer-deps参数,问题未解决。

错误信息

npm notice
npm notice New minor version of npm available! 9.2.0 -> 9.3.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.3.1>
npm notice Run `npm install -g npm@9.3.1` to update!
npm notice
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @agm/core@3.0.0-beta.0
npm ERR! Found: @angular/common@14.2.12
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"^14.2.0" from the root project
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!     @angular/cdk@"^14.2.4" from the root project
npm ERR!     peer @angular/cdk@"14.2.7" from @angular/material@14.2.7
npm ERR!     node_modules/@angular/material
npm ERR!       @angular/material@"^14.2.4" from the root project
npm ERR!       1 more (@angular/material-moment-adapter)
npm ERR!   5 more (@angular/forms, @angular/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/core@3.0.0-beta.0
npm ERR! node_modules/@agm/core
npm ERR!   @agm/core@"^3.0.0-beta.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/common@10.2.5
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/core@3.0.0-beta.0
npm ERR!   node_modules/@agm/core
npm ERR!     @agm/core@"^3.0.0-beta.0" 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.

项目package.json内容

{
  "name": "web-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^3.0.0-beta.0",
    "@angular/animations": "^14.2.0",
    "@angular/cdk": "^14.2.4",
    "@angular/common": "^14.2.0",
    "@angular/compiler": "^14.2.0",
    "@angular/core": "^14.2.0",
    "@angular/forms": "^14.2.10",
    "@angular/material": "^14.2.4",
    "@angular/material-moment-adapter": "^14.2.5",
    "@angular/platform-browser": "^14.2.10",
    "@angular/platform-browser-dynamic": "^14.2.0",
    "@angular/router": "^14.2.10",
    "@manekinekko/angular-web-bluetooth": "^11.2.2",
    "@types/googlemaps": "^3.39.13",
    "@types/maplibre-gl": "^1.14.0",
    "@types/web-bluetooth": "^0.0.16",
    "bootstrap": "^3.4.1",
    "maplibre-gl": "^1.15.3",
    "moment": "^2.29.4",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.2.2",
    "@angular/cli": "~14.2.2",
    "@angular/compiler-cli": "^14.2.0",
    "@types/geojson": "^7946.0.10",
    "@types/jasmine": "~4.0.0",
    "jasmine-core": "~4.3.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.7.2"
  }
}

解决方案

核心问题是@agm/core@3.0.0-beta.0仅支持Angular 9/10,但项目使用的是Angular 14,依赖版本不兼容。以下是可行的解决途径:

  • 升级@agm/core到兼容Angular 14的版本
    将package.json中@agm/core的版本改为^3.1.1(或最新兼容稳定版),然后执行npm install。

  • 使用npm的overrides强制解决依赖冲突
    在package.json中添加overrides字段,强制指定@agm/core使用项目中的Angular版本:

    "overrides": {
      "@agm/core": {
        "@angular/common": "$@angular/common",
        "@angular/core": "$@angular/core"
      }
    }
    

    添加后重新执行npm install,npm会忽略@agm/core的peer依赖要求,直接使用项目已安装的Angular包。

  • 降级Node.js版本
    NodeJS 19搭配npm 9对peer依赖的检查更严格,Windows环境可能使用更低版本的Node/npm未触发错误。尝试降级到Node.js 16(LTS版本),再执行npm install --legacy-peer-deps。

  • 清理缓存后重试
    先清理npm缓存:

    npm cache clean --force
    

    删除node_modules和package-lock.json:

    rm -rf node_modules package-lock.json
    

    然后重新执行npm install --legacy-peer-deps。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 14:45:25