【问题标题】:ERESOLVE unable to resolve dependency tree - for @mui/materialERESOLVE 无法解析依赖树 - 对于 @mui/material
【发布时间】:2022-01-05 02:37:14
【问题描述】:

我正在尝试按照主页上的说明安装 ma​​terial UI,但出现依赖关系树错误:

C:\dev\shape-shop-front-end>npm install @mui/material
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree        
npm ERR! 
npm ERR! While resolving: my-app@0.1.0
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   react@"^16.13.1" from the root project
npm ERR!   peer react@">=16.8.0" from @emotion/react@11.7.1
npm ERR!   node_modules/@emotion/react
npm ERR! node_modules/@mui/material
npm ERR!   @mui/material@"*" from the root project
npm ERR!

在我的 package.json 我有 "react": "^16.13.1"

据我了解,此错误表示 MUI 包需要响应 16.8.0

【问题讨论】:

    标签: npm material-ui


    【解决方案1】:

    确实,它的一个子依赖项,名为@emotion/react@11.7.1,列出了您必须满足的以下对等依赖项:

    "peerDependencies": {
      "@babel/core": "^7.0.0",
      "react": ">=16.8.0"
    }
    

    来源:https://github.com/emotion-js/emotion/blob/main/packages/react/package.json

    我认为这与新版本的 NPM 如何处理对等依赖项有关:https://github.blog/2021-02-02-npm-7-is-now-generally-available/

    由于您的反应版本似乎还可以,我会接受这个建议:

    您可以选择使用 --force 重试以绕过冲突或使用 --legacy-peer-deps 命令完全忽略对等依赖项(此行为类似于版本 4-6)。

    【讨论】:

      【解决方案2】:

      看起来更新 package.json 中的依赖项是现在实现这一点的唯一方法。

      $ npm install -g npm-check-updates
      $ ncu -u
      $ npm install 
      

      或查看how to update each dependency in package.json

      更新后,现在尝试安装您的材质 UI。

      【讨论】:

        【解决方案3】:

        尝试使用 --force。 这对我有用

        npm install @mui/material --force
        

        我感觉这是最近 React 升级带来的依赖冲突...

        【讨论】:

          猜你喜欢
          • 2021-08-04
          • 2021-09-25
          • 1970-01-01
          • 2021-03-24
          • 2022-01-25
          • 1970-01-01
          • 1970-01-01
          • 2022-10-07
          • 2021-06-16
          相关资源
          最近更新 更多