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

React项目安装showdown失败,遇依赖冲突问题求助

React项目安装showdown时ERESOLVE依赖冲突的解决方法

问题描述

执行npm install --save react-showdown或npm install showdown时触发ERESOLVE依赖错误,核心原因是项目中已安装的react-mde@11.5.0要求peer依赖react@^17.0.0,但当前项目使用的是react@18.2.0,两者版本冲突导致安装失败。

报错详情:

$ npm install --save react-showdown

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: react-mde@11.5.0
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@"^18.2.0" from react-dom@18.2.0
npm ERR!   node_modules/react-dom
npm ERR!     react-dom@"^18.2.0" from the root project
npm ERR!   peer react@"*" from react-split@2.0.14
npm ERR!   node_modules/react-split
npm ERR!     react-split@"^2.0.14" from the root project
npm ERR!   2 more (the root project, react-showdown)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from react-mde@11.5.0
npm ERR! node_modules/react-mde
npm ERR!   react-mde@"^11.5.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0" from react-mde@11.5.0
npm ERR!   node_modules/react-mde
npm ERR!     react-mde@"^11.5.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/mofer/.npm/_logs/2023-09-11T11_22_26_434Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/mofer/.npm/_logs/2023-09-11T11_22_26_434Z-debug-0.log

解决方法

方法1:使用npm兼容参数绕过peer依赖检查

直接在安装命令后添加--legacy-peer-deps(推荐,采用旧版npm的peer依赖处理逻辑,避免强制覆盖):

npm install --save react-showdown --legacy-peer-deps

或使用--force(强制安装,可能引入潜在兼容性问题,谨慎使用):

npm install --save react-showdown --force

方法2:升级react-mde到兼容React 18的版本

react-mde后续版本已支持React 18,升级后即可解决依赖冲突:

# 升级到最新版本
npm install react-mde@latest
# 再安装react-showdown
npm install --save react-showdown

方法3:降级React到17.x版本(不推荐)

如果必须保留react-mde@11.5.0,可降级React版本适配:

# 安装React 17.x版本
npm install react@^17.0.2 react-dom@^17.0.2
# 再安装react-showdown
npm install --save react-showdown

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 06:13:32