You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Expo 49升级至54后React Native集成Firebase Authentication应用崩溃无控制台错误

Fixing Firebase Auth Crash After Upgrading to Expo 54

Hey there, I’ve helped several developers fix exactly this crash when jumping from Expo 49 to 54 with Firebase Authentication. Looking at your firebaseConfig.js code, the issue boils down to Firebase SDK version mismatches, duplicate Auth initialization, and hidden type errors from those //@ts-ignore lines that only surface in production builds. Let’s break down the fixes:

1. Sync All Firebase SDK Versions

Expo 54 (built on React Native 0.74) requires Firebase SDK v10.x or newer, and all firebase/* packages must use the same version—mixing versions creates silent dependency conflicts that crash builds.

  • Open your package.json and make sure every Firebase-related dependency shares the same version. For example:
    "dependencies": {
      "firebase": "^10.12.0",
      "@firebase/auth": "^10.12.0" // Match this to your firebase version
    }
    
  • Reinstall dependencies and fix any mismatches with Expo’s helper:
    npx expo install --fix
    

2. Fix Auth Initialization to Avoid Duplicates

Your current code initializes Auth without checking if an instance already exists. In production builds, this can trigger duplicate initialization crashes. Update your firebaseConfig.js like this:

import { FirebaseOptions, initializeApp, getApps, getApp } from "firebase/app";
import { initializeAuth, getReactNativePersistence, getAuth } from "firebase/auth";
import ReactNativeAsyncStorage from "@react-native-async-storage/async-storage";

const firebaseConfig: FirebaseOptions = {
  apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
  authDomain: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_AUTH_DOMAIN,
  databaseURL: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_DATABASE_URL,
  projectId: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID,
  storageBucket: process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID,
  measurementId: process.env.EXPO_PUBLIC_FIREBASE_MEASUREMENT_ID,
};

// Initialize Firebase App only if no existing instance exists
const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();

// Initialize Auth safely (no duplicates)
export const auth = getApps().length === 0 
  ? initializeAuth(app, {
      persistence: getReactNativePersistence(ReactNativeAsyncStorage),
    })
  : getAuth(app);

3. Remove //@ts-ignore and Fix Type Errors

Those //@ts-ignore lines are hiding type mismatches that the TypeScript compiler would normally catch. In production builds, these unaddressed types can lead to silent crashes.

  • First, make sure your @types/react and @types/react-native versions match Expo 54’s requirements (React 18.2.0, React Native 0.74.3).
  • If getReactNativePersistence throws a type error, explicitly type it to resolve the issue:
    import type { Persistence } from "@firebase/auth";
    const persistence: Persistence = getReactNativePersistence(ReactNativeAsyncStorage);
    

4. Test in Production Mode Locally First

Before running a full EAS Build, test your app in production mode locally to catch errors early:

npx expo start --no-dev --minify

This mimics the production build environment, and you’ll see detailed console errors if something’s broken—way easier than debugging a remote build log.

5. Double-Check Your EAS Build Config

If you’re using EAS Build, ensure your eas.json is configured for Expo 54. Here’s a basic production config to verify:

{
  "build": {
    "production": {
      "channel": "production",
      "expo": {
        "runtimeVersion": {
          "policy": "appVersion"
        }
      }
    }
  }
}

Also, review the EAS Build logs carefully—look for errors in the Installing dependencies or Bundling JavaScript stages, as these often reveal hidden issues.


Follow these steps, and your production build should stop crashing. I’ve seen this exact scenario multiple times, and the root cause is almost always a combination of version mismatches and unsafe initialization logic.

内容的提问来源于stack exchange,提问作者Bello Shehu

火山引擎 最新活动