所有 React Native Firebase 模块必须是同一版本 - 不能使用 Auth

All React Native Firebase modules must be of the same version - can't use Auth

我从 Invertase 提供的入门工具包安装了 RNF。我正在使用 RNF 应用程序、数据库、分析、授权。一切正常,直到我需要 auth 模块。它在应用程序启动时抛出错误(Android,还没有尝试 iOS):

    ...\node_modules\react-native\Libraries\Core\ExceptionsManager.js:86 
You've attempted to require '@react-native-firebase/auth' version '6.0.3', however, 
the '@react-native-firebase/app' module is of a different version (6.0.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.

不过我查了package.json所有的模块都是6.0.3版本的,我的package.json看起来也不错:

{
  "name": "meditationapp",
  "version": "6.0.3",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "run:android": "react-native run-android",
    "run:ios": "react-native run-ios --simulator=\"iPhone 11 Pro Max\"",
    "build:apk": "cd android && ./gradlew assembleRelease",
    "test": "jest",
    "prepare": "patch-package",
    "storybook": "start-storybook -p 7007"
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.2",
    "@react-native-community/netinfo": "^4.4.0",
    "@react-native-firebase/analytics": "6.0.3",
    "@react-native-firebase/app": "6.0.3",
    "@react-native-firebase/auth": "6.0.3",
    "@react-native-firebase/database": "6.0.3",
    "@typescript-eslint/eslint-plugin": "^2.3.3",
    "@typescript-eslint/parser": "^2.3.3",
    ...

在 App.tsx 中导入:

import firebase from '@react-native-firebase/app'
import database from '@react-native-firebase/database'
import analytics from '@react-native-firebase/analytics'
import auth from '@react-native-firebase/auth'

我尝试过的事情:

  1. 删除node_modules和运行npm install
  2. 安装了 v6.0.0 而不是 6.0.3
  3. 已删除android/app/build

想不出还有什么可以尝试的,但错误并没有消失。 它在分析和数据库方面运行良好,只有身份验证是个问题。

发现这是缓存的问题。

  1. 我删除了 npm 缓存和 metro bundler 缓存(手动,在 Windows 它们位于 C:\Users\Appdata\Roaming)
  2. 删除了项目中的 node_modules 文件夹
  3. 运行 npm install

该项目现在拥有所有版本为 6.0.3 的 RNF 模块

我创建了一个项目:

npx @react-native-community/cli init --template=@react-native-firebase/template <name>

我遇到了这个问题。但是后来我创建了一个像 react-native init <name> 这样的基本项目并安装了

@react-native-firebase/app @react-native-firebase/auth

或任何产品,问题得到改善。

我遇到了同样的问题。您应该注意 @react-native-firebase/... 的所有包都等于 @react-native-firebase/app.

要解决这个问题你需要 update the relevant packages 然后 reset the npm cache:

  1. npm update @react-native-firebase/app
  2. npm update @react-native-firebase/analytics
  3. npm update @react-native-firebase/.. //所有的 firebase 包(已更新)

最后重置 npm 缓存

  1. npm start -- --reset-cache