【问题标题】:NPM Dependency Resolution ConflictsNPM 依赖解决冲突
【发布时间】:2023-02-02 16:02:08
【问题描述】:

当我运行 node install 时,我得到以下输出:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: google-map-react@2.1.10
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR!   react@"^18.1.0" from the root project
npm ERR!   peer react@">=16.3" from @deck.gl/react@8.7.8
npm ERR!   node_modules/@deck.gl/react
npm ERR!     @deck.gl/react@"8.7.8" from deck.gl@8.7.8
npm ERR!     node_modules/deck.gl
npm ERR!       deck.gl@"^8.7.8" from the root project
npm ERR!   15 more (@emotion/react, @emotion/styled, @mui/base, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.0.0 || ^17.0.0" from google-map-react@2.1.10
npm ERR! node_modules/google-map-react
npm ERR!   google-map-react@"^2.1.10" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peer react@"^16.0.0 || ^17.0.0" from google-map-react@2.1.10
npm ERR!   node_modules/google-map-react
npm ERR!     google-map-react@"^2.1.10" 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": "frontend",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@emotion/react": "^11.9.0",
        "@emotion/styled": "^11.8.1",
        "@mui/icons-material": "^5.6.2",
        "@mui/material": "^5.6.3",
        "deck.gl": "^8.7.8",
        "react": "^18.1.0",
        "react-dom": "^18.1.0",
        "react-router": "^6.3.0",
        "react-router-dom": "^5.1.2",
        "react-scripts": "5.0.1",
        "react-transition-group": "^4.3.0"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": "react-app"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }
}

我已经尝试过 npm install --legacy-peer-depsnpm install --force 都没有更改错误消息。我也试过 npm install --legacy-peer-deps --save google-maps-react 看看我是否必须为每个包单独执行此操作,但没有成功。我知道这个错误比较常见,跟npm版本和可怕的破坏性变化.

有谁知道我可以采取的任何其他步骤?

【问题讨论】:

  • 尝试检查您的节点版本及其兼容性

标签: node.js reactjs npm


【解决方案1】:

从我的电脑版本的节点 18.0.0 转到最新的 16 LTS 后,我通过运行 npm install --legacy-peer-deps 解决了这个问题。

【讨论】:

    【解决方案2】:

    发现:react@18.1.0 错误!同行反应@“^16.8.0 || ^17.0.0”

    1. npm 配置设置 legacy-peer-deps true
    2. npm install --save --legacy-peer-deps
    3. npm 安装 --force

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
    【解决方案3】:

    我通过运行以下说明解决了它

    1. npm 配置设置 legacy-peer-deps true
    2. npm install --save --legacy-peer-deps
    3. npm 安装 --force

      #node.js #reactjs #npm

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2022-07-14
      • 2019-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多