最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializ

programmeradmin6浏览0评论

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)
   }) 

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app-compat/no-app)

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
  • 1 Why aren't you using the db you created after initialiation? – Doug Stevenson Commented Mar 27 at 12:16
  • I tried doing that but instead the error went away but nothing is added to my database. probably I'm not doing it right. can you please show me an example code? I didn't seem to find a solution in their documentation – Eric Uche Commented Mar 27 at 12:24
  • 2 There is plenty of documentation for you to follow. Requests for sample code are off-topic for Stack Overflow. Instead, you should focus on creating a minimal complete reproducible example that anyone can copy and use to observe the same result and see what you might be doing wrong. I don't see that what you're showing is complete enough to see what the specific problem is. I suggest avoiding firebase/compat modules unless you absolutely know that you need them. – Doug Stevenson Commented Mar 27 at 12:27
  • thanks I was able to solve it by following the documentation link you provided – Eric Uche Commented Mar 27 at 13:16
Add a comment  | 

1 Answer 1

Reset to default 1

You 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 };

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论