Reputation: 2701
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
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