【问题标题】:Could not resolve dependency error peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4无法解决来自@material-ui/core@4.12.4 的依赖错误 peer react@\"^16.8.0 || ^17.0.0\"
【发布时间】:2022-08-20 11:39:30
【问题描述】:

在尝试安装npm install 时,我遇到了错误,有人可以建议,解决问题的最佳方法是什么。由于这个错误,我的构建在 netlify 中失败了。

错误: $

npm install
        npm ERR! code ERESOLVE
        npm ERR! ERESOLVE unable to resolve dependency tree
        npm ERR!
        npm ERR! While resolving: sssclub@0.1.0
        npm ERR! Found: react@18.1.0
        npm ERR! node_modules/react
        npm ERR!   react@\"^18.0.0\" from the root project
        npm ERR!
        npm ERR! Could not resolve dependency:
        npm ERR! peer react@\"^16.8.0 || ^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

{
      \"name\": \"sssclub\",
      \"version\": \"0.1.0\",
      \"private\": true,
      \"dependencies\": {
        \"@emotion/react\": \"^11.9.0\",
        \"@emotion/styled\": \"^11.8.1\",
        \"@material-ui/core\": \"^4.12.4\",
        \"@mui/icons-material\": \"^5.8.3\",
        \"@mui/material\": \"^5.8.3\",
        \"@testing-library/jest-dom\": \"^5.16.4\",
        \"@testing-library/react\": \"^13.1.1\",
        \"@testing-library/user-event\": \"^13.5.0\",
        \"axios\": \"^0.27.2\",
        \"cors\": \"^2.8.5\",
        \"express\": \"^4.18.1\",
        \"multer\": \"^1.4.4\",
        \"mysql2\": \"^2.3.3\",
        \"path\": \"^0.12.7\",
        \"react\": \"^18.0.0\",
        \"react-dom\": \"^18.0.0\",
        \"react-hook-form\": \"^7.31.2\",
        \"react-router-dom\": \"^6.3.0\",
        \"react-scripts\": \"^5.0.1\",
        \"react-tweet-embed\": \"^2.0.0\",
        \"sequelize\": \"^6.20.1\",
        \"web-vitals\": \"^2.1.4\"
      },
      \"engines\": {
        \"node\": \"16.14.2\",
        \"npm\": \"8.5.0\"
      },
      \"proxy\": \"http://localhost:8000\",
      \"scripts\": {
        \"start\": \"react-scripts start\",
        \"start:server\": \"node src/server.js\",
        \"build\": \"react-scripts build\",
        \"test\": \"react-scripts test\",
        \"eject\": \"react-scripts eject\",
        \"preinstall\": \"npx npm-force-resolutions\"
      },
      \"eslintConfig\": {
        \"extends\": [
          \"react-app\",
          \"react-app/jest\"
        ]
      },
      \"browserslist\": {
        \"production\": [
          \">0.2%\",
          \"not dead\",
          \"not op_mini all\"
        ],
        \"development\": [
          \"last 1 chrome version\",
          \"last 1 firefox version\",
          \"last 1 safari version\"
        ]
      }
    }

    标签: reactjs react-hooks


    【解决方案1】:

    尝试这个

    npm config set legacy-peer-deps true
    npm i
    

    【讨论】:

    • 我需要先删除 package-lock.json, node_modules 然后再安装吗?
    • 不行的话先直接试试,不如去掉。
    • 好的,当然,会尝试回复
    • 安装成功但现在我收到此错误...插件“react”在“package.json»eslint-config-react-app»C:\Proj\work\sss\node_modules\eslint-config-react-之间发生冲突app\base.js”和“BaseConfig » C:\Proj\Work\sss\node_modules\eslint-config-react-app\base.js”。
    【解决方案2】:

    删除 node_modules 文件夹并尝试以下命令

    npm config set legacy-peer-deps true
    npm install
    

    【讨论】:

      【解决方案3】:

      请使用 npm install --legacy-peer-deps 代替 npm install。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-04
        • 2019-03-25
        • 2022-07-30
        • 2023-02-12
        • 1970-01-01
        • 2021-07-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多