reactjs 在react中安装材料ui时出错

mmvthczy  于 2023-01-02  发布在  React
关注(0)|答案(1)|浏览(194)

我尝试使用material ui core,但是在react和typescript应用程序中使用npm安装时出现错误。我在项目根目录中使用的命令是:第一个月
Material UI website
我得到的错误是:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @mui/core@5.0.0-alpha.54
npm ERR! Found: @types/react@18.0.15
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/base@5.0.0-alpha.95
npm ERR!   node_modules/@mui/base
npm ERR!     @mui/base@"5.0.0-alpha.95" from @mui/material@5.10.3
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"^5.10.3" from the root project
npm ERR!       1 more (@mui/icons-material)
npm ERR!   peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/icons-material@5.10.3
npm ERR!   node_modules/@mui/icons-material
npm ERR!     @mui/icons-material@"^5.10.3" from the root project
npm ERR!   9 more (@mui/private-theming, @mui/system, @mui/types, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@"^16.8.6 || ^17.0.0" from @mui/core@5.0.0-alpha.54
npm ERR! node_modules/@mui/core
npm ERR!   @mui/core@"^5.0.0-alpha.54" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @types/react@17.0.49
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@"^16.8.6 || ^17.0.0" from @mui/core@5.0.0-alpha.54
npm ERR!   node_modules/@mui/core
npm ERR!     @mui/core@"^5.0.0-alpha.54" 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/username/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2022-09--debug-0.log
user@User'sPC projectName % npm install @mui/material @emotion/react @emotion/styled
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @mui/core@5.0.0-alpha.54
npm ERR! Found: @types/react@18.0.15
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/base@5.0.0-alpha.95
npm ERR!   node_modules/@mui/base
npm ERR!     @mui/base@"5.0.0-alpha.95" from @mui/material@5.10.3
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"^5.10.3" from the root project
npm ERR!       1 more (@mui/icons-material)
npm ERR!   peerOptional @types/react@"^17.0.0 || ^18.0.0" from @mui/icons-material@5.10.3
npm ERR!   node_modules/@mui/icons-material
npm ERR!     @mui/icons-material@"^5.10.3" from the root project
npm ERR!   9 more (@mui/private-theming, @mui/system, @mui/types, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@"^16.8.6 || ^17.0.0" from @mui/core@5.0.0-alpha.54
npm ERR! node_modules/@mui/core
npm ERR!   @mui/core@"^5.0.0-alpha.54" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @types/react@17.0.49
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@"^16.8.6 || ^17.0.0" from @mui/core@5.0.0-alpha.54
npm ERR!   node_modules/@mui/core
npm ERR!     @mui/core@"^5.0.0-alpha.54" 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/username/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2022-09-debug-0.log

我的相关package.json是:

"dependencies": {
    "@emotion/react": "^11.10.4",
    "@emotion/styled": "^11.10.4",
    "@mui/core": "^5.0.0-alpha.54",
    "@mui/icons-material": "^5.10.3",
    "@mui/material": "^5.10.3",
    "@mui/styled-engine-sc": "^5.10.3",
},

我删除了@mui/core dependency,然后尝试执行以下命令:npm i --save @mui/core正如评论中的答案所建议的那样,但是我得到了以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving:projectname@0.1.0
npm ERR! Found: react@18.2.0
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@"^17.0.2" from @mui/core@5.0.0-alpha.54
npm ERR! node_modules/@mui/core
npm ERR!   @mui/core@"^5.0.0-alpha.54" 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/username/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2022-09--debug-0.log

我不知道这个错误意味着什么,所以将感谢任何帮助,谢谢!

wa7juj8i

wa7juj8i1#

运行这些命令

  1. npm配置集传统对等部署为真
  2. npm i -保存@mui/核心
  3. npm i @mui/样式

相关问题