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

执行npm install遇ERESOLVE依赖冲突(Gatsby/React新手求助)

解决npm install时的ERESOLVE依赖冲突问题

你遇到的是npm依赖版本冲突问题:gatsby-plugin-mdx@5.5.0要求@mdx-js/react@^2.0.0作为对等依赖,但你的项目当前安装的是@mdx-js/react@1.6.22,版本不匹配导致安装失败。

错误日志详情:

pegasus@pegasus:~/Documents/MyWebsite/blog-main$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: gatsby-plugin-mdx@5.5.0
npm ERR! Found: @mdx-js/react@1.6.22
npm ERR! node_modules/@mdx-js/react
npm ERR!   @mdx-js/react@"^1.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @mdx-js/react@"^2.0.0" from gatsby-plugin-mdx@5.5.0
npm ERR! node_modules/gatsby-plugin-mdx
npm ERR!   dev gatsby-plugin-mdx@"^5.5.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @mdx-js/react@2.2.1
npm ERR! node_modules/@mdx-js/react
npm ERR!   peer @mdx-js/react@"^2.0.0" from gatsby-plugin-mdx@5.5.0
npm ERR!   node_modules/gatsby-plugin-mdx
npm ERR!     dev gatsby-plugin-mdx@"^5.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! /home/pegasus/.npm/_logs/2023-01-27T07_02_53_230Z-eresolve-report.txt

可通过以下方式解决:

  • 升级依赖版本(推荐):将@mdx-js/react升级到符合插件要求的版本,执行命令:

    npm install @mdx-js/react@^2.0.0 --save
    

    完成后再运行npm install即可正常安装。

  • 使用npm兼容模式:如果暂时不想升级依赖,可通过--legacy-peer-deps参数跳过对等依赖检查:

    npm install --legacy-peer-deps
    

    也可以用--force强制安装,但这种方式可能引发其他潜在问题,不推荐优先使用。

  • 降低插件版本:若不想升级@mdx-js/react,可修改package.json中gatsby-plugin-mdx的版本为支持@mdx-js/react@1.x的版本(比如4.x系列),将版本号改为^4.0.0后,再运行npm install。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 17:45:49