【问题标题】:Material UI , Next12, React 18材质 UI,Next12,React 18
【发布时间】:2022-01-19 06:26:33
【问题描述】:

我正在尝试试用最新版本的 NextJS(版本 12),以使我的项目能够访问 SSR ServerComponents 和 Http 流。

MaterialUI 可以在 Next 12.0.7 和 React 17 中正常工作(使用 npx create-next-app@latest 安装)

当我这样做时

npm install react@beta react-dom@beta

然后

npm install @mui/material @mui/styled-engine-sc styled-components --save

给予

(base) marcfielding@MBP meta-ui % npm install @mui/material @mui/styled-engine-sc styled-components --save

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: meta-ui@undefined
npm ERR! Found: react@18.0.0-rc.0-next-f2a59df48-20211208
npm ERR! node_modules/react
npm ERR!   react@"^18.0.0-beta-24dd07bd2-20211208" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.2" from @mui/material@5.2.3
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"*" 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/marcfielding/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/marcfielding/.npm/_logs/2021-12-09T16_48_20_688Z-debug.log

这只是等待 MUI 赶上来吗?或者有没有我可以安装的版本,我之前按照here 的说明进行操作?

【问题讨论】:

  • @Summer 下面的回答非常有效。 NPM@7 有一个古怪的对等依赖解析系统,你可以在这里阅读更多ostack.cn/?qa=538022

标签: reactjs npm material-ui next.js server-side-rendering


【解决方案1】:

如果你不介意使用 yarn,这里有一个你可以使用你想要的 deps 的 repo:https://github.com/MiniDeathStar/material-ui-next12-react-18

如果你想使用 npm,你可以运行:

npm install @mui/material @mui/styled-engine-sc styled-components --legacy-peer-deps

Mui shouldn't be broken by React@18。我已经很好地将它们一起使用了。 Npm 是一个挑剔的包管理器,所以只要有机会,我就会提倡 Yarn 3。

【讨论】:

  • Heya Summer,感谢您的回复,并为缓慢的回复道歉 - 我今天回到办公桌前,将测试一下,非常感谢!
  • 别担心赏金到期,我仍然会为您整理 - 刚上班第一天忙得不可开交,我会尽快处理 :-)
  • 嘿,Yarn 是我让它工作的方式,可能值得编辑这个答案以反映这一点,抱歉慢了 - 已经有一段时间了。我很确定我只是安装了 YARN,而不是任何特别的东西
  • @MrkFldig 很高兴它成功了!是经典的 Yarn 还是 Yarn v3?我写答案时的 NextJS 版本与 Yarn 3 的 PnP 功能不兼容,所以我不得不将 nodeLinker 设置为 node-modules。我不想写这么详细的说明,所以我只是做了一个回购。经典纱线不使用 PnP,因此它可以开箱即用。但是当前的 NextJS 版本 (12.1) 支持 PnP,因此 Yarn 3 现在也可以开箱即用了。
  • 你知道我不记得了,但我真的要启动一个新建项目,所以我会尽快回复你!
猜你喜欢
  • 2019-07-14
  • 2020-10-23
  • 2018-07-31
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2018-10-22
  • 2021-04-18
  • 1970-01-01
相关资源
最近更新 更多