Skip to content

Failed to initialize auth with persistence: [Error: Component auth has not been registered yet] #8988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
patrickkeenan opened this issue Apr 30, 2025 · 8 comments

Comments

@patrickkeenan
Copy link

Operating System

Mac OS

Environment (if applicable)

Expo 52 / React Native

Firebase SDK Version

11.6.1

Firebase SDK Product(s)

Auth

Project Tooling

Environment
firebase: 11.6.1
react-native: 0.79.1
expo: 53.0.1
@react-native-async-storage/async-storage: 2.1.2

Detailed Problem Description

When using the Firebase JS SDK (firebase@11.6.1) with React Native (react-native@0.79.1), initializing Auth without explicitly providing AsyncStorage results in:

The warning appears even though @react-native-async-storage/async-storage is installed.
The error [Error: Component auth has not been registered yet] is thrown on initialization.
This occurs when using the standard getAuth() import from firebase/auth.

Steps and code to reproduce issue

Install dependencies as above.
Initialize Firebase and Auth in a React Native project.
Observe the warning and error on app start.

Expected Behavior
Auth should initialize without error if AsyncStorage is installed.
If AsyncStorage is required, the SDK should detect and use it automatically, or provide clear instructions for React Native users.

@patrickkeenan patrickkeenan added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Apr 30, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: auth Repro Needed needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Apr 30, 2025
@iM-GeeKy
Copy link

iM-GeeKy commented May 1, 2025

I've been using this for the last 2 years with no problems until I upgraded as well. Did I miss something in an update?

File
import AsyncStorage from "@react-native-async-storage/async-storage";
import { initializeApp } from "firebase/app";
import { initializeAuth, getReactNativePersistence } from "firebase/auth";

import getEnvVars from "./Environment";

/** Dynamically fetch environment variables. */
const { ENVIRONMENT } = getEnvVars();

/** Initializes the {@link firebase} application with configuration options. */
const FirebaseApp = initializeApp(
ENVIRONMENT === "production"
  ? require("./FirebaseConfig.prod.json")
  : require("./FirebaseConfig.dev.json"),
);

/**
* This function allows more control over the Auth instance than getAuth, which uses platform-specific defaults to supply the Dependencies.
* In general, getAuth is the easiest way to initialize Auth and works for most use cases. Use initializeAuth if you need control over which
* persistence layer is used, or to minimize bundle size if you're not using either signInWithPopup or signInWithRedirect.
*
* @see https://firebase.google.com/support/release-notes/js#authentication
*/
const FirebaseAuth = initializeAuth(FirebaseApp, {
persistence: getReactNativePersistence(AsyncStorage),
});

/** Export the variables so the rest of the app can have access to them. */
export { FirebaseAuth, FirebaseApp };

I'm using the following related packages

{
  "@react-native-async-storage/async-storage": "^2.1.2",
  "expo": "^53.0.4",
  "firebase": "^11.6.1",
  "react": "19.0.0",
  "react-dom": "19.0.0",
  "react-native": "~0.79.2"
}

@tanvir-ahmad
Copy link

I tried to use it in my React Native Expo project with Expo version 53. It causes the same problem. Then I tried with my older project (Expo SDK 52) and then it worked. I think the Firebase JS SDK needs an update for Expo SDK 53 and higher.

@patrickkeenan
Copy link
Author

Here's the bug on the expo side of things. Between firebase or expo, it must be something. I gotta switch off firebase if this continues

expo/expo#36496

@patrickkeenan
Copy link
Author

Unresolved past issue here
#8798

@Enigma94
Copy link

Enigma94 commented May 2, 2025

Im having the same issue, using Expo SDK 53.0.5 and firebase 11.6.1, it works fine on 52

@brentvatne
Copy link

it could possibly be related to metro enabling support for package.json:exports -- expo/expo#36551. try disabling it as described in that discussion topic

@petrusvanegeraat
Copy link

it could possibly be related to metro enabling support for package.json:exports -- expo/expo#36551. try disabling it as described in that discussion topic

Thanks @brentvatne. This resolved the issue for me. I've added it to the list https://github.com/expo/expo/discussions/36551#discussioncomment-13021826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants