gpt4 book ai didi

react-native - NPM 安装在 react-native 项目 : "unable to resolve dependency tree for react & react-dom" 上失败

转载 作者:行者123 更新时间:2023-12-05 04:19:20 25 4
gpt4 key购买 nike

我将开始与另一个开发人员一起开发一个 react-native 项目,但在此之前我已经开发了另一个项目并且它在 android 模拟器上运行没有错误。

我从 https://github.com/ismail-benlaredj/ld-vetrinalive-reactnative 克隆了项目并运行 npm install 导致此错误:

PS G:\Workspaces\React Native\ld-vetrinalive-reactnative> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: nativetestapp@0.0.0
npm ERR! Found: react@18.0.0
npm ERR! node_modules/react
npm ERR! react@"18.0.0" from the root project
npm ERR! peer react@"*" from native-base@3.4.25
npm ERR! node_modules/native-base
npm ERR! native-base@"^3.4.25" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.2.0" from react-dom@18.2.0
npm ERR! node_modules/react-dom
npm ERR! peer react-dom@"*" from native-base@3.4.25
npm ERR! node_modules/native-base
npm ERR! native-base@"^3.4.25" 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.
npm ERR!
npm ERR! See C:\Users\DEV-ABDOU\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\DEV-ABDOU\AppData\Local\npm-cache\_logs\2022-12-17T21_35_51_753Z-debug.log

这是eresolve-report.txt:

# npm resolution error report

2022-12-17T21:35:51.742Z

While resolving: nativetestapp@0.0.0
Found: react@18.0.0
node_modules/react
react@"18.0.0" from the root project
peer react@"*" from native-base@3.4.25
node_modules/native-base
native-base@"^3.4.25" from the root project

Could not resolve dependency:
peer react@"^18.2.0" from react-dom@18.2.0
node_modules/react-dom
peer react-dom@"*" from native-base@3.4.25
node_modules/native-base
native-base@"^3.4.25" from the root project

Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

Raw JSON explanation object:

{
"code": "ERESOLVE",
"current": {
"name": "react",
"version": "18.0.0",
"whileInstalling": {
"name": "nativetestapp",
"version": "0.0.0",
"path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
},
"location": "node_modules/react",
"isWorkspace": false,
"dependents": [
{
"type": "prod",
"name": "react",
"spec": "18.0.0",
"from": {
"location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
}
},
{
"type": "peer",
"name": "react",
"spec": "*",
"from": {
"name": "native-base",
"version": "3.4.25",
"whileInstalling": {
"name": "nativetestapp",
"version": "0.0.0",
"path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
},
"location": "node_modules/native-base",
"isWorkspace": false,
"dependents": [
{
"type": "prod",
"name": "native-base",
"spec": "^3.4.25",
"from": {
"location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
}
}
]
}
}
]
},
"currentEdge": {
"type": "prod",
"name": "react",
"spec": "18.0.0",
"from": {
"location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
}
},
"edge": {
"type": "peer",
"name": "react",
"spec": "^18.2.0",
"error": "INVALID",
"from": {
"name": "react-dom",
"version": "18.2.0",
"whileInstalling": {
"name": "nativetestapp",
"version": "0.0.0",
"path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
},
"location": "node_modules/react-dom",
"isWorkspace": false,
"dependents": [
{
"type": "peer",
"name": "react-dom",
"spec": "*",
"from": {
"name": "native-base",
"version": "3.4.25",
"whileInstalling": {
"name": "nativetestapp",
"version": "0.0.0",
"path": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
},
"location": "node_modules/native-base",
"isWorkspace": false,
"dependents": [
{
"type": "prod",
"name": "native-base",
"spec": "^3.4.25",
"from": {
"location": "G:\\Workspaces\\React Native\\ld-vetrinalive-reactnative"
}
}
]
}
}
]
}
},
"strictPeerDeps": false,
"force": false
}

  • 我不知道我是否应该包含冗长的 npm 日志(让我知道)。

问题:

  • 我不知道如何解释错误消息(解决对等依赖性)
  • 控制台建议使用标志:--force 或 --legacy-peer-deps,风险由我承担,我犹豫是否要这样做,因为它说
... to accept an incorrect (and potentially broken) dependency resolution.

这就是我在这里寻求帮助的原因。

关于 SOF 的类似问题:

React Native app's npm install fails due to conflicting versions of react and react-dom

到目前为止我尝试了什么:

我在网上看到的大多数答案都建议我更新我的全局 react-native-cli 但根据文档 here他们要求您卸载它。

还有一些答案指出一些环境变量没有正确设置,这对我来说不是这种情况,因为我的其他项目工作正常。

最佳答案

试试这个。

npm cache verify
rm -rf node_modules
rm package-lock.json
npm i

这将清理 npm 缓存并重建 package-lock.json和节点模块

如果它不起作用,请告诉我,我会克隆该存储库并查看。

关于react-native - NPM 安装在 react-native 项目 : "unable to resolve dependency tree for react & react-dom" 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74837803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com