reactjs - 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
.
解决方案
这应该允许更灵活的对等依赖解决方案
npm install --legacy-peer-deps
推荐阅读
- java - 从 Netbeans 部署时无法启动 Tomcat 应用程序
- docker - 如何在 Docker 映像的 .NetCore 项目中启动 Kestrel
- c - 请求成员 .. 在不是结构的东西中
- flutter - Hero Animation 完成后启动 Widget Animation
- perl - 使用 perl 代码中的 usseradd 时出错:无法锁定 /etc/passwd
- javascript - 期望在箭头函数错误结束时返回一个值
- c++ - 未能为 Visual Studio 2017 构建 boost 1.68
- python - 使用带有 Pipenv 的 .env 文件修改 PYTHONPATH
- python - TensorFlow 处理代码在 Linux Mint 上的 Python 中返回失败
- html - Particles.js,如何使包含动画粒子的画布的高度跨越其在小屏幕上的父元素