I'm trying to use firestore database in my expo project but I can't seem to initialize it correctly as it seems something has changed from last time I used it.
I initialized it in my apps root layout like so
import { getFirestore } from "firebase/firestore/lite";
import firebase from 'firebase/compat/app'
import { initializeApp } from 'firebase/app';
const firebaseConfig = {
apiKey: "my api key",
authDomain: "my domain",
projectId: "my project id",
storageBucket: "my bucket",
messagingSenderId: "my sender id",
appId: "my app id",
measurementId: "some id"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
but when I attempt to add data to the database with this code i get an error
firebase.firestore().collection('requests').doc('trucks').collection('order')
.add({
name: 'John doe',
email: '[email protected],
}).then(() => {
console.log('added')
// navigation.navigate(SearchView)
})
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app)
I'm trying to use firestore database in my expo project but I can't seem to initialize it correctly as it seems something has changed from last time I used it.
I initialized it in my apps root layout like so
import { getFirestore } from "firebase/firestore/lite";
import firebase from 'firebase/compat/app'
import { initializeApp } from 'firebase/app';
const firebaseConfig = {
apiKey: "my api key",
authDomain: "my domain",
projectId: "my project id",
storageBucket: "my bucket",
messagingSenderId: "my sender id",
appId: "my app id",
measurementId: "some id"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
but when I attempt to add data to the database with this code i get an error
firebase.firestore().collection('requests').doc('trucks').collection('order')
.add({
name: 'John doe',
email: '[email protected],
}).then(() => {
console.log('added')
// navigation.navigate(SearchView)
})
Share Improve this question edited Mar 27 at 13:49 Frank van Puffelen 600k85 gold badges890 silver badges860 bronze badges Recognized by Google Cloud Collective asked Mar 27 at 12:05 Eric UcheEric Uche 1478 bronze badges 4 |FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app)
1 Answer
Reset to default 1You imported firebase/compat/app but initialized Firebase using initializeApp from firebase/app. The compat version does not recognize this initialization.
Here is the most simple snippit that might help you.
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore/lite";
const firebaseConfig = {
apiKey: "my api key",
authDomain: "my domain",
projectId: "my project id",
storageBucket: "my bucket",
messagingSenderId: "my sender id",
appId: "my app id",
measurementId: "some id"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export { app, db };
db
you created after initialiation? – Doug Stevenson Commented Mar 27 at 12:16firebase/compat
modules unless you absolutely know that you need them. – Doug Stevenson Commented Mar 27 at 12:27