简体   繁体   中英

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

So I'm building mobile app via veu.js -> vuetify module using realtime database from firebase.

One of my views - Pract.vue need to retrive data from database.

<template>
  <div class="pa-6 text-center">
    <h1>Practice Mode</h1>
  </div>
</template>



<script>
import firebase from "firebase";
import "firebase/database";

var ref = firebase.database().ref("ang");


</script>

I added firebase.initializeApp(firebaseConfig); with data generated by firebase console to main.js file and import firebase from "firebase"

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify';
import firebase from "firebase";

// Xs in original code are real data

var firebaseConfig = {
    apiKey: "X",
    authDomain: "X",
    databaseURL: "X",
    projectId: "X",
    storageBucket: "X",
    messagingSenderId: "X",
    appId: "X",
    measurementId: "X"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

Vue.config.productionTip = false

new Vue({
    router,
    store,
    vuetify,
    render: h => h(App)
}).$mount('#app')

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

I've tried import firebase from 'firebase/app' both in view and main.js -> same alert.

I had this same issue when trying to use firebase in the router index.ts file. I had to initialize firebase in index.ts to get it to work.

  • Try changing the import statement to

    import firebase from "firebase/compat/app";
  • I faced the same error while trying to have an separate file for accessing firebase services (which is neither a component nor a file created by vue-cli). In my case it is sampleAPI.ts . So to solve this, I had to import the above mentioned statement and then initialized the app in sampleAPI.ts that solved my problem.

     firebase.initializeApp(firebaseConfig);

You need to call

firebase.initializeApp();

before any calls to firebase can be made

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM