尝试使用 npm 安装 mui core 时出错

fle*_*ank 2 html reactjs material-ui

我刚刚部署了一个新的 create-react-app,但仍然收到相同的错误消息。我安装了 MUI,但收到“无法解析依赖关系树”消息

    npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: eat-blended-web@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
npm ERR! node_modules/@material-ui/core
npm ERR!   @material-ui/core@"*" 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! See /Users/rodriguezmedia/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/rodriguezmedia/.npm/_logs/2022-05-13T00_57_27_262Z-debug-0.log
rodriguezmedia@Frankies-MacBook-Air-2 eat-blended-web % 
Run Code Online (Sandbox Code Playgroud)

小智 11

不要使用“npm install @material-ui/core”,只需参考“npm install @mui/material”,对于 mui 图标只需安装“npm install @mui/icons-material”。

有关更多详细信息,请访问“https://www.npmjs.com/package/@mui/icons-material”此页面。


pez*_*pez 5

该错误告诉您,您尝试安装的软件包具有react@"^16.8.0 || ^17.0.0"其对等依赖项,但您当前正在使用react@18.1.0.

--legacy-peer-deps您可以通过在命令末尾添加来解决此问题并安装软件包。例如:

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

请记住,对等依赖项是包设计用于使用的模块。使用此标志继续安装可能会导致意外的、有时甚至是破坏性的更改。由于 React 18 是新的,一些包尚未更新以将其专门包含在其对等依赖项中。