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

未添加--legacy-peer-deps时ANTV相关依赖npm安装失败

解决@ant-design/charts安装时的ERESOLVE依赖冲突问题

未添加--legacy-peer-deps选项时,安装ANTV相关依赖(@ant-design/charts)会失败,npm报错信息如下:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @ant-design/charts@1.4.2
npm ERR! Found: @ant-design/icons@5.0.1
npm ERR! node_modules/@ant-design/icons
npm ERR! @ant-design/icons@"^5.0.1" from the root project
npm ERR! @ant-design/icons@"^5.0.0" from antd@5.1.6
npm ERR! node_modules/antd
npm ERR! antd@"^5.1.6" from the root project
npm ERR! peer antd@">=4.4.2 || >=5.0.0-beta.0" from @antv/x6-react-components@1.1.20

项目package.json配置如下:

{
  "engines": {
    "node": "18.x",
    "npm": "8.x"
  },
  "dependencies": {
    "@ant-design/charts": "^1.4.2",
    "@ant-design/icons": "^5.0.1",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "antd": "^5.1.6",
    "classnames": "^2.3.2",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.8.0",
    "react-scripts": "5.0.1",
    "serve": "^14.2.0",
    "web-vitals": "^2.1.4"
  }
}

解决方案

  • 临时安装:执行带有--legacy-peer-deps参数的安装命令,跳过严格的peer依赖校验:
    npm install --legacy-peer-deps
    
  • 永久配置:在项目根目录创建.npmrc文件,添加以下内容,后续安装默认启用legacy模式:
    legacy-peer-deps=true
    
  • 版本兼容升级:如果希望保持严格的peer依赖校验,可以升级@ant-design/charts到兼容@ant-design/icons@5.x的版本,比如安装最新稳定版:
    npm install @ant-design/charts@latest
    

原因解析

@ant-design/charts@1.4.2的peer依赖要求中,可能指定了@ant-design/icons的较低版本(如4.x系列),而当前项目已安装@ant-design/icons@5.0.1。npm 7及以上版本默认启用严格的peer依赖版本校验规则,当依赖版本不匹配时就会抛出ERESOLVE错误。--legacy-peer-deps参数会让npm回退到npm 6的宽松解析逻辑,忽略这类版本冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 01:01:10