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

Next.js App Router+TypeScript项目安装MUI报错问题求助

问题原因及解决方案

原因分析

  • 版本兼容性不匹配:当前MUI稳定版(v5系列)的依赖声明仅支持React 17/18,而你的项目使用的是React 19候选版本(RC),npm的依赖解析机制会判定版本范围冲突,抛出ERESOLVE错误。
  • 生态适配滞后:Next.js 15属于较新的预发布版本,依赖的React 19 RC尚未正式发布,大部分UI组件库(包括MUI)还未完成对该版本的全面适配和测试。

解决方案

方案一:降级到稳定兼容版本(推荐)

如果不需要React 19的新特性,这是最稳妥的选择:

  1. 卸载现有依赖:
    npm uninstall next react react-dom
    
  2. 安装稳定版Next.js和React:
    npm install next@14 react@18 react-dom@18 typescript@latest
    
  3. 重新安装MUI:
    npm install @mui/material @emotion/react @emotion/styled
    

方案二:使用MUI的React 19适配预览版

MUI可能发布了适配React 19的测试版本,可尝试安装带next标签的预览包:

npm install @mui/material@next @emotion/react@next @emotion/styled@next

注意:预览版可能存在未修复的bug,仅适合开发测试或必须使用React 19特性的场景。

方案三:通过npm overrides强制兼容

在项目的package.json中添加overrides字段,强制MUI使用项目中的React版本:

{
  "overrides": {
    "react": "$react",
    "react-dom": "$react-dom"
  }
}

添加完成后,重新执行MUI安装命令:

npm install @mui/material @emotion/react @emotion/styled

注意:此方法会绕过依赖版本检查,可能引发运行时兼容性问题,需完成全面测试后再用于生产环境。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 22:12:39