0

I use Firebase on a lot of my projects, but I never used it with vue 3 before. For an Ionic Project, I am using Vue 3 with typescript. What I would do to initialize Firebase projects on Vue 2 is, on the main.js file, this:

new Vue({
  router,
  created() {
    firebase.initializeApp(firebaseConfig)
  }}).$mount('#app')

On vue 3 - main.ts -, tried:

const app = createApp(App, {
  created(){
    firebase.initializeApp(firebaseConfig)
  }
})

But I get the message:

Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()

It works if the initializeApp() is outside "app definition", in the root of the file. What could be the problem? Thanks

1
  • It looks like you are trying to invoke a Firebase method before Firebase is initialized. Can you please share the complete code? Commented Jun 22, 2021 at 4:22

1 Answer 1

0

You need to initiate Firebase at the start of your app before even Vue is created, ideally in a dedicated firebase.js script that manages Firebase within your app.

firebase.initializeApp(firebaseConfig)
new Vue({
  router
}).$mount('#app')
Sign up to request clarification or add additional context in comments.

2 Comments

Undefined variable firebase.
you haven't imported or declared the variable. this is not a firebase issue but a general code issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.