包安装在React 18中不起作用

huangapple go评论60阅读模式
英文:

Package installation with React 18 doesn't work

问题

当尝试安装任何包时,我遇到以下错误。请帮助我找到解决此问题的方法。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @material-ui/core@4.12.4
npm ERR! Found: @types/react@18.0.31
npm ERR! node_modules/@types/react
npm ERR!   @types/react@^18.0.31 from the root project
npm ERR!   peerOptional @types/react@* from @material-ui/types@5.1.0
npm ERR!   node_modules/@material-ui/types
npm ERR!     @material-ui/types@5.1.0 from @material-ui/core@4.12.4
npm ERR!     node_modules/@material-ui/core
npm ERR!       @material-ui/core@^4.12.4 from the root project
npm ERR!     @material-ui/types@5.1.0 from @material-ui/styles@4.11.5
npm ERR!     node_modules/@material-ui/styles
npm ERR!       @material-ui/styles@^4.11.5 from @material-ui/core@4.12.4
npm ERR!       node_modules/@material-ui/core
npm ERR!         @material-ui/core@^4.12.4 from the root project
npm ERR!   9 more (@mui/base, @mui/icons-material, @mui/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@^16.8.6 || ^17.0.0 from @material-ui/core@4.12.4
npm ERR! node_modules/@material-ui/core
npm ERR!   @material-ui/core@^4.12.4 from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @types/react@17.0.59
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@^16.8.6 || ^17.0.0 from @material-ui/core@4.12.4
npm ERR!   node_modules/@material-ui/core
npm ERR!     @material-ui/core@^4.12.4 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.

我的package.json:
https://github.com/orchidenver/weather-app-react/blob/test/package.json

英文:

when trying to install any package I come across with an error below. Please, help my to find a solution for this problem.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @material-ui/core@4.12.4
npm ERR! Found: @types/react@18.0.31
npm ERR! node_modules/@types/react
npm ERR!   @types/react@&quot;^18.0.31&quot; from the root project
npm ERR!   peerOptional @types/react@&quot;*&quot; from @material-ui/types@5.1.0
npm ERR!   node_modules/@material-ui/types
npm ERR!     @material-ui/types@&quot;5.1.0&quot; from @material-ui/core@4.12.4
npm ERR!     node_modules/@material-ui/core
npm ERR!       @material-ui/core@&quot;^4.12.4&quot; from the root project
npm ERR!     @material-ui/types@&quot;5.1.0&quot; from @material-ui/styles@4.11.5
npm ERR!     node_modules/@material-ui/styles
npm ERR!       @material-ui/styles@&quot;^4.11.5&quot; from @material-ui/core@4.12.4
npm ERR!       node_modules/@material-ui/core
npm ERR!         @material-ui/core@&quot;^4.12.4&quot; from the root project
npm ERR!   9 more (@mui/base, @mui/icons-material, @mui/material, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/react@&quot;^16.8.6 || ^17.0.0&quot; from @material-ui/core@4.12.4
npm ERR! node_modules/@material-ui/core
npm ERR!   @material-ui/core@&quot;^4.12.4&quot; from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @types/react@17.0.59
npm ERR! node_modules/@types/react
npm ERR!   peerOptional @types/react@&quot;^16.8.6 || ^17.0.0&quot; from @material-ui/core@4.12.4
npm ERR!   node_modules/@material-ui/core
npm ERR!     @material-ui/core@&quot;^4.12.4&quot; 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.

<!-- end snippet -->

My package.json:
https://github.com/orchidenver/weather-app-react/blob/test/package.json

答案1

得分: 1

你正在尝试安装不兼容React 18的Material UI v4。只有Material UI v5完全支持React 18,所以你需要更新到mui 5。

首先卸载**@material-ui/core v4**,

然后安装mui5:npm install @mui/material @emotion/react @emotion/styled

英文:

you are trying to install material ui v4 which is not compatible with react 18. Material UI v5 is the only version that fully supports React 18, so you'll need to update to mui 5

first uninstall @material-ui/core v4

then install mui5 : npm install @mui/material @emotion/react @emotion/styled

huangapple
  • 本文由 发表于 2023年5月13日 20:34:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定