Reputation: 437
I am getting this error when I was trying to connect firebase with my React Native App.
Firebase Error: No Firebase App [DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app)
I have added my code here-
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
// Your web app's Firebase configuration
const RNfirebaseConfig = {
apiKey: "........",
authDomain: "note-app-rn.firebaseapp.com",
projectId: "note-app-rn",
storageBucket: "note-app-rn.appspot.com",
messagingSenderId: ".....",
appId: "......"
};
const app = initializeApp(RNfirebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);
Upvotes: 9
Views: 43487
Reputation: 10502
Did it happen during migration to new React Native
architecture?
Remember to change your import:
@import Firebase;
in AppDelegate.m
#import <Firebase.h>
in AppDelegate.mm
Upvotes: 7
Reputation: 93
The main source of the error is related to initialize config setting.
Checkout this usage;
import firebase from 'firebase/compat/app'
import 'firebase/compat/auth'
import 'firebase/compat/firestore'
export const firebaseConfig = {
apiKey: "............",
authDomain: "............",
projectId: "............",
storageBucket: "............",
messagingSenderId: "............",
appId: "............",
measurementId: "............"
}
if (!firebase.apps.length){
firebase.initializeApp(firebaseConfig);
}
Upvotes: 1
Reputation: 2339
try this,
import firebase from '@react-native-firebase/app';
import '@react-native-firebase/auth';
import '@react-native-firebase/firestore';
const RNfirebaseConfig = {
apiKey: "........",
authDomain: "note-app-rn.firebaseapp.com",
projectId: "note-app-rn",
storageBucket: "note-app-rn.appspot.com",
messagingSenderId: ".....",
appId: "......"
};
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(RNfirebaseConfig )
} else {
app = firebase.app()
}
const db = firebase.firestore();
const auth = firebase.auth();
Upvotes: 7