首页 > 解决方案 > ERESOLVE 无法解析我的反应原生 Web 项目中的依赖树

问题描述

我得到了一个我正在尝试制作的反应本机 Web 模板。所以我安装@reduxjs/toolkit了我的状态管理。但是我在安装后运行项目时遇到了错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: react@16.9.0
npm ERR! node_modules/react
npm ERR!   peer react@"16.9.0" from react-native@0.61.5
npm ERR!   node_modules/react-native
npm ERR!     peer react-native@"^0.61.0" from @react-native-community/cli@3.2.1
npm ERR!     node_modules/@react-native-community/cli
npm ERR!       @react-native-community/cli@"^3.0.0" from react-native@0.61.5
npm ERR!     react-native@"^0.61.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @reduxjs/toolkit@"^1.6.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@17.0.2
npm ERR! node_modules/react
npm ERR!   peerOptional react@"^16.14.0 || ^17.0.0" from @reduxjs/toolkit@1.6.0
npm ERR!   node_modules/@reduxjs/toolkit
npm ERR!     @reduxjs/toolkit@"^1.6.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.

这些是每个目录的 package.json 文件的依赖项和 devDependencies。根/包/公共

{
  "name": "@monorepo/common",
  "version": "1.0.0",
  "main": "dist/index.js",
  "scripts": {
    "build": "rm -rf dist && tsc",
    "watch": "tsc --watch"
  },
  "license": "MIT",
  "dependencies": {
    "@reduxjs/toolkit": "^1.6.0",
    "grunt-sync": "^0.8.2",
    "react-native": "^0.61.5"
  },
  "devDependencies": {
    "@types/react-native": "^0.61.16",
    "grunt": "^1.4.1",
    "grunt-contrib-watch": "^1.1.0",
    "typescript": "^3.8.2"
  }
}

根/包/移动

"dependencies": {
    "react": "16.8.6",
    "react-native": "0.60.5"
  },
  "devDependencies": {
    "@monorepo/common": "1.0.0",
    "@babel/core": "^7.5.0",
    "@babel/runtime": "^7.5.0",
    "@react-native-community/eslint-config": "^0.0.3",
    "@types/jest": "^24.0.18",
    "@types/react": "^16.9.2",
    "@types/react-native": "^0.60.14",
    "@types/react-test-renderer": "^16.9.0",
    "babel-jest": "^24.1.0",
    "jest": "^24.1.0",
    "metro-react-native-babel-preset": "0.54.1",
    "react-test-renderer": "16.8.6",
    "typescript": "^3.6.3"
  }

根/包/网络

"dependencies": {
    "@monorepo/common": "1.0.0",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-native-web": "^0.12.1",
    "react-scripts": "3.4.0",
    "typescript": "~3.7.2"
  },
"devDependencies": {
    "@types/react-native": "^0.61.16",
    "cross-env": "^7.0.3",
    "uuid": "^8.3.2"
  }

我尝试升级到最新的包,但我仍然遇到同样的错误,这次冲突在其他地方,并且顶级依赖项仍然是@react-native-community/cli.

标签: reactjsreact-native

解决方案


这应该允许更灵活的对等依赖解决方案

npm install --legacy-peer-deps

推荐阅读