执行npm install安装MUI依赖时遇ERESOLVE依赖树解析错误求助
解决npm安装MUI依赖时的ERESOLVE依赖树错误
以下是几个实测有效的解决步骤,按顺序尝试即可:
- 清理npm缓存,清除可能残留的旧依赖信息:
npm cache clean --force - 删除项目里的
node_modules文件夹和package-lock.json文件(Windows用户用对应命令),彻底重置依赖状态:
之后重新执行安装命令:# macOS/Linux rm -rf node_modules package-lock.json # Windows rmdir /s /q node_modules && del package-lock.jsonnpm install @mui/material @emotion/react @emotion/styled - 如果还是报错,添加
--legacy-peer-deps参数忽略peer依赖的严格检查(这是解决此类冲突最常用的方案):npm install @mui/material @emotion/react @emotion/styled --legacy-peer-deps - 升级npm到最新版本,旧版本的依赖解析逻辑可能存在缺陷:
npm install -g npm@latest - 检查项目是否存在旧版
material-ui包(注意是不带@mui前缀的旧包),如果有先卸载再重新安装MUI:npm uninstall material-ui npm install @mui/material @emotion/react @emotion/styled
内容的提问来源于stack exchange,提问作者Arjun R.
相关产品推荐
相关产品推荐

