Oleksii Zelenko
Oleksii Zelenko

Reputation: 2701

An error occurred while creating an application on [email protected] + NUXT

I create an application with [email protected] I get the error

Created a folder plugins add file firebase.js

import { initializeApp } from 'firebase/app'
import { getFirestore } from 'firebase/firestore'
const firebaseConfig = {
  apiKey: '',
  authDomain: '',
  databaseURL: '',
  projectId: '',
  storageBucket: '',
  messagingSenderId: '',
  appId: ''
}
let firebaseApp
try {
  firebaseApp = getApp()
} catch (e) {
  firebaseApp = initializeApp(firebaseConfig)
}
const db = getFirestore(firebaseApp, {})
export { db }

nuxt.config.js

...
plugins: [    
    '~/plugins/firebase.js'
  ],
...

I get the error:

error 'getApp' is not defined no-undef

Upvotes: 0

Views: 128

Answers (1)

DIGI Byte
DIGI Byte

Reputation: 4163

getApp() is not a built-in method and must be called from the appropriate library, in this case: FirebaseApp.getApp()

import { initializeApp, getApps, getApp } from "firebase/app";
getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();

OR

if (FirebaseApp.getApps(context).isEmpty()) {
    FirebaseApp.initializeApp(context);
}

Upvotes: 1

Related Questions