安装 Material ui 和下一个 js(有和没有打字稿)错误的问题

Problem in Installing Material ui with next js (with and without typescript) error

我是新手,下一个 js 很抱歉我的愚蠢问题, 我正在尝试在新的下一个 js 应用程序中安装 material ui (我使用了“npx create-next-app@latest”), 我正在使用 Material ui 文档和 ts 部分 (https://mui.com/guides/typescript/#main-content)

我在 cli / 终端中遇到以下错误:

npm install @mui/material @emotion/react @emotion/styled
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR!   peer react@">=16.8.0" from @emotion/react@11.8.2      
npm ERR!   node_modules/@emotion/react
npm ERR!     @emotion/react@"*" from the root project
npm ERR!     peerOptional @emotion/react@"^11.5.0" from @mui/material@5.5.3
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"*" from the root project
npm ERR!     1 more (@emotion/styled)
npm ERR!   1 more (@emotion/styled)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/material@5.5.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!

我曾尝试使用 material ui 组件,但出现编译错误, 即使我在 nextjs 中尝试过(没有 ts 和有) 并带有标志:--force,或--legacy-peer-deps

请帮忙!非常感谢!我只需要开始我的项目!

在带有和不带有打字稿的 next-js 中安装 material ui

如果我有这个问题,我会删除 package.json 并重新安装它,然后我尝试安装 Material。你试过了吗?

运行这个命令。刚刚为我工作。

npm install @mui/material @emotion/react @emotion/styled --force

我也删除了我的 node_modules 并再次安装以确保安全。它发现了 0 个漏洞。