我使用
创建了一个反应项目npm init -y
npm install react react-dom
然后我尝试安装material UI
npm install @material-ui/core
出现错误
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"^18.2.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/[email protected]
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!
npm ERR! For a full report see:
npm ERR! /.npm/_logs/2023-10-17T20_20_42_394Z-eresolve-report.txt
我不明白这个错误消息想说什么。使用
--force
我能够安装 Material UI,但我不明白这里有什么问题。
这个解决方案似乎也解决了这个问题,但我认为我不应该首先出现错误,我不应该设置旧的对等部门。
https://stackoverflow.com/a/72597065/21970496
https://v4.mui.com/getting-started/installation/ 这里说
react >= 16.8.0 and react-dom >= 16.8.0 are peer dependencies
我的react版本是18但仍然不起作用
尝试一下:
npm config set legacy-peer-deps true
npm i