javascript 为什么会抛出与peer相关的“无法解析依赖树”,如何修复?

vxf3dgd4  于 2023-05-05  发布在  Java
关注(0)|答案(1)|浏览(144)

在我的React Native应用程序中,我想使用以下命令安装React Native Firebase Auth模块:

npm install --save @react-native-firebase/auth

但我得到以下错误:

ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: woo@0.0.1
npm ERR! Found: @react-native-firebase/app@14.12.0
npm ERR! node_modules/@react-native-firebase/app
npm ERR!   @react-native-firebase/app@"^14.11.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @react-native-firebase/app@"16.5.0" from @react-native-firebase/auth@16.5.0
npm ERR! node_modules/@react-native-firebase/auth
npm ERR!   @react-native-firebase/auth@"*" 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.

我的packaje.json文件:

"react-native": "0.68.2",
"@react-native-firebase/app": "^14.11.1",
"@react-native-firebase/messaging": "^14.11.1",

先谢谢你了!

okxuctiv

okxuctiv1#

说明

如果您将@react-native-firebase/auth安装在npm init -y之后的单独文件夹中,并通过查看node_modules打开其文件夹,您将在其package.json中看到以下内容:

"peerDependencies": {
  "@react-native-firebase/app": "16.5.0"
},

这意味着它需要@react-native-firebase/app16.5.0版本才能工作,而您的package.json版本为14.11.1;这就是问题所在。
但问题是@react-native-firebase/messaging版本14.11.1需要@react-native-firebase/app的版本14.12.0,就像它在package.json中一样:

"peerDependencies": {
   "@react-native-firebase/app": "14.12.0"
 },

溶液

解决办法是找到一个能让所有人都同意的版本。在您的特定情况下,一种方法是首先将它们都升级到最新版本:

npm i --save @react-native-firebase/messaging@latest @react-native-firebase/app@latest

然后安装@react-native-firebase/auth

npm i --save @react-native-firebase/auth

相关问题