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



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

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

PS G:WorkspacesReact Nativeld-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:UsersDEV-ABDOUAppDataLocalnpm-cacheeresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:UsersDEV-ABDOUAppDataLocalnpm-cache_logs2022-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, or --legacy-peer-deps在我自己的风险,我对这样做犹豫不决,因为它说
... to accept an incorrect (and potentially broken) dependency resolution.

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

关于软件的类似问题:

React Native app's npm install失败,原因是React和React -dom版本冲突

我已经试过了:

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

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

试试这个

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

这将清理npm缓存并重新构建package-lock.json和node_modules

如果它不能工作,让我知道,我会克隆的repo,看看。

相关内容

  • 没有找到相关文章

最新更新