admin 管理员组文章数量: 1086019
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 };
本文标签:
版权声明:本文标题:javascript - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializ 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744091230a2532073.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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