You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo项目中Authentication error: app._isFirebaseServerApp未定义求助

问题:Authentication error: app._isFirebaseServerApp is not a function (it is undefined)

问题描述

在Expo开发环境中,主项目运行时触发错误:Authentication error: app._isFirebaseServerApp is not a function (it is undefined)。相同功能在另一项目可正常运行,单独运行app.js中的相关代码也会触发相同错误。

package.json配置

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@expo/metro-runtime": "~3.1.3",
    "@firebase/app": "^0.9.29",
    "@firebase/auth": "^1.6.2",
    "@firebase/database": "^1.0.3",
    "@react-native-async-storage/async-storage": "^1.23.1",
    "@react-native-community/masked-view": "^0.1.0",
    "@react-native-firebase/app": "^18.7.3",
    "@react-native-firebase/auth": "^18.7.3",
    "@react-navigation/bottom-tabs": "*",
    "@react-navigation/native": "6.0.0",
    "@react-navigation/native-stack": "^6.9.12",
    "@react-navigation/stack": "^6.3.16",
    "@types/react": "~18.2.14",
    "expo": "~50.0.14",
    "expo-constants": "~14.4.2",
    "expo-status-bar": "~1.11.1",
    "firebase": "^10.11.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.73.6",
    "react-native-dropdown-picker": "^5.4.6",
    "react-native-firebase": "^5.6.0",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-paper": "*",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-vector-icons": "^10.0.3",
    "react-native-web": "~0.19.6",
    "react-navigation": "*",
    "react-navigation-stack": "*"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "react-native-modal": "^13.0.1"
  },
  "private": true
}

错误截图

错误截图


解决方案

这个错误的核心是多套Firebase依赖版本冲突:你同时安装了@react-native-firebase/app(v18)、react-native-firebase(v5)、firebase(v10)以及@firebase/app(v0.9),这些分属不同Firebase SDK分支,互相不兼容,导致内部判断属性app._isFirebaseServerApp未被正确定义。

修复步骤:

  1. 卸载所有冲突依赖
    只保留适配Expo环境的官方firebase包,卸载其余重复分支:

    npm uninstall @react-native-firebase/app @react-native-firebase/auth react-native-firebase @firebase/app @firebase/auth @firebase/database
    
  2. 重新安装正确依赖
    安装指定版本的firebase包:

    npm install firebase@10.11.1
    
  3. 修正Firebase初始化代码
    使用firebase官方包的标准导入和初始化方式:

    import { initializeApp } from 'firebase/app';
    import { getAuth } from 'firebase/auth';
    
    const firebaseConfig = {
      // 你的Firebase项目配置
    };
    
    const app = initializeApp(firebaseConfig);
    const auth = getAuth(app);
    
  4. 清除缓存并重启项目

    expo r -c
    

注意事项:

  • Expo环境下不要混用react-native-firebase(原生端专用SDK)和firebase(web/Expo通用SDK),两者初始化逻辑完全不同。
  • 优先使用firebase官方包,无需额外配置原生依赖,更适配Expo开发流程。

内容的提问来源于stack exchange,提问作者Yunus dinc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 09:00:58