无法解决依赖关系

Could not resolve dependency

我一直在尝试下载模板以开始对其进行自定义。下载后,应该使用 npm installyarn install 安装所有本地依赖项。我已经完成了这两项工作,并且两次都遇到了同样的错误。此外,我尝试按照错误消息中的建议,对 --force--legacy-peer-deps 使用相同的命令。我发现了一个 GitHub 讨论这个精确问题和其他一些堆栈溢出线程的问题。我已经尝试了我遇到的一切,但它不起作用。而且我已经安装了推荐版本的节点,所以这也不是问题,正如另一个线程中所建议的那样。

错误信息如下所示。

While resolving: @mui/material@5.2.0
npm ERR! Found: @emotion/react@11.4.1
npm ERR! node_modules/@emotion/react
npm ERR!   @emotion/react@"11.4.1" from the root project
npm ERR!   peer @emotion/react@"^11.0.0-rc.0" from @emotion/styled@11.3.0
npm ERR!   node_modules/@emotion/styled
npm ERR!     @emotion/styled@"11.3.0" from the root project
npm ERR!     peerOptional @emotion/styled@"^11.3.0" from @mui/material@5.2.0
npm ERR!     node_modules/@mui/material
npm ERR!       @mui/material@"5.2.0" from the root project
npm ERR!       1 more (@mui/icons-material)
npm ERR!     1 more (@mui/styled-engine)
npm ERR!   1 more (@mui/styled-engine)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @emotion/react@"^11.5.0" from @mui/material@5.2.0
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"5.2.0" from the root project
npm ERR!   peer @mui/material@"^5.0.0" from @mui/icons-material@5.2.0
npm ERR!   node_modules/@mui/icons-material
npm ERR!     @mui/icons-material@"5.2.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @emotion/react@11.7.1
npm ERR! node_modules/@emotion/react
npm ERR!   peerOptional @emotion/react@"^11.5.0" from @mui/material@5.2.0
npm ERR!   node_modules/@mui/material
npm ERR!     @mui/material@"5.2.0" from the root project
npm ERR!     peer @mui/material@"^5.0.0" from @mui/icons-material@5.2.0
npm ERR!     node_modules/@mui/icons-material
npm ERR!       @mui/icons-material@"5.2.0" 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.

模板:https://www.creative-tim.com/product/material-dashboard-react?ref=readme-mdr#

GitHub 问题:https://github.com/creativetimofficial/material-dashboard-react/issues/171

提前致谢。

问题是模板中使用的特定版本 @emotion/react 不再有效。

为了解决这个问题,我去了 package.json 并手动将版本从 11.4.1 更改为 11.5.011.5.0 似乎解决了所用模板的问题。

从 package.json 文件升级您的版本并 运行 再次“npm install”命令