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

升级Node至18.12.1与npm至9.2.0后npm install上游依赖冲突求助

问题

将Node升级至18.12.1、npm升级至9.2.0后,执行npm install始终出现上游依赖冲突错误,无法成功运行。已执行以下命令:

npm install -g npm-check-updates
ncu -u
npm install 

执行npm install后得到如下报错信息:

npm install                                                                                                                                                                            ─╯
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: hipersigno@undefined
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   react@"^18.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from react-svgmt@1.2.0
npm ERR! node_modules/react-svgmt
npm ERR!   react-svgmt@"^1.2.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.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/mchildress/.npm/_logs/2023-01-09T16_27_29_875Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mchildress/.npm/_logs/2023-01-09T16_27_29_875Z-debug-0.log

需解决该上游依赖冲突问题,使npm install可成功运行。

解决方案

方法1:启用npm兼容模式安装

直接添加--legacy-peer-deps参数,让npm恢复到v6版本的peer依赖处理逻辑,忽略版本冲突:

npm install --legacy-peer-deps

若临时需要强制安装(不推荐长期使用,可能引发潜在运行问题),可执行:

npm install --force

方法2:降级React至兼容版本

修改项目根目录的package.json,将react的版本改为^17.0.0(同时同步修改react-dom版本保持一致),然后执行:

npm install

方法3:升级react-svgmt到支持React 18的版本

先查看react-svgmt的最新版本:

npm show react-svgmt version

若存在支持React 18的版本,直接更新依赖:

npm install react-svgmt@latest

再执行npm install完成安装。

方法4:使用overrides强制指定依赖版本(npm 8.3+支持)

在package.json中添加overrides字段,强制react-svgmt适配当前项目的React版本:

{
  "overrides": {
    "react-svgmt": {
      "react": "^18.2.0"
    }
  }
}

添加后执行:

npm install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 09:15:32