如何解决此Firebase模块版本错误?

时间:2020-03-28 16:31:18

标签: react-native

这是package.json中我的Firebase依赖项列表:

"@react-native-firebase/admob": "^6.2.0",
"@react-native-firebase/app": "^6.2.0",
"@react-native-firebase/auth": "^6.2.0",
"@react-native-firebase/crashlytics": "^6.2.0",
"@react-native-firebase/messaging": "^6.2.0",

我刚刚在该列表中添加了最后一个“消息传递”依赖项,然后运行了npm install。我为组件添加了以下导入:

import messaging from '@react-native-firebase/messaging';

然后,我在组件功能之一中包含以下代码行:

      const enabled = await firebase.messaging().hasPermission();

我的应用当前返回以下错误:

Error: Requiring module "node_modules\@react-native-firebase\messaging\lib\index.js", which threw an exception: Error: You've attempted to require '@react-native-firebase\messaging' version '6.3.4', however, the '@react-native-firebase\app' module is of a different version (6.2.0).  All React Native Firebase modules must be of the same version.  Please ensure they match up in your package.json file and re-run yarn/npm install

I inspected my project's node_modules\@react-native-firebase\messaging\package.json.  Here's a subset of some of the version refs within that file:

  "_from": "@react-native-firebase/messaging@^6.2.0",
  "_id": "@react-native-firebase/messaging@6.3.4",
  "_requested": {
    "raw": "@react-native-firebase/messaging@^6.2.0",
    "rawSpec": "^6.2.0",
    "fetchSpec": "^6.2.0"
  },
  "_resolved": "https://registry.npmjs.org/@react-native-firebase/messaging/-/messaging-6.3.4.tgz",
  "_spec": "@react-native-firebase/messaging@^6.2.0",
  "version": "6.3.4"

因此,看起来我配置的^ 6.2.0版本规范已按预期读取,但是随后npm安装过程的某些方面将安装重定向到版本6.3.4。知道为什么会这样吗?所有Firebase模块都必须具有相同的版本,因此,如果我要使用Firebase消息传递模块,则需要在项目包中将所有其他Firebase模块的版本设置为“ ^ 6.3.0” .json?还是我有其他解决方法?

0 个答案:

没有答案