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

Material UI Icons安装失败,ERESOLVE依赖树解析错误求助

解决Material UI Icons安装时的ERESOLVE依赖冲突问题

问题重现

尝试以下命令安装Material UI Icons均失败:

npm install @material-ui/icons 
npm install @material-ui/icons --force 
npm i @mui/icons-material @mui/material

报错信息:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: netflix@0.1.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"^18.0.0" from the root project
npm ERR! peer react@">=16.8.0" from @emotion/react@11.8.2
npm ERR! node_modules/@emotion/react
npm ERR! peerOptional @emotion/react@"^11.5.0" from @mui/material@5.5.3
npm ERR! node_modules/@mui/material
npm ERR! @mui/material@"^5.5.3" from the root project
npm ERR! 1 more (@mui/icons-material)
npm ERR! peer @emotion/react@"^11.0.0-rc.0" from @emotion/styled@11.8.1
npm ERR! node_modules/@emotion/styled
npm ERR! peerOptional @emotion/styled@"^11.3.0" from @mui/material@5.5.3
npm ERR! node_modules/@mui/material
npm ERR! @mui/

核心原因

  1. 混用了旧版Material UI(@material-ui/icons,v4版本)和新版MUI(@mui/icons-material,v5版本)的安装命令,版本不统一导致依赖混乱。
  2. 当前安装的@mui/material@5.5.3版本对React 18的适配不完善,npm 7+默认启用的严格peer依赖检查触发了冲突。

解决方案

方案1:统一安装适配React 18的最新稳定版MUI包

  1. 卸载现有冲突的依赖包:
npm uninstall @material-ui/icons @mui/material @mui/icons-material @emotion/react @emotion/styled
  1. 删除本地依赖缓存和锁文件:
rm -rf node_modules package-lock.json
  1. 安装最新版的MUI核心包及图标:
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled

方案2:使用legacy-peer-deps跳过严格peer依赖检查

如果无法升级MUI版本,可通过npm的legacy-peer-deps选项绕过依赖冲突检查:

npm install @mui/material @mui/icons-material --legacy-peer-deps

注意事项

  • 避免同时使用@material-ui/*(v4)和@mui/*(v5)的包,两者是不同版本的Material UI,会导致依赖冲突。
  • React 18发布后,建议使用MUI v5.8.0及以上版本,这些版本已完善对React 18的支持。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 21:45:36