Cruel
Cruel

Reputation: 11

undefined is not an object (evaluating 'firebase.initializeApp')

Whenevr I open the debugger in safari I get an error saying that undefined is not an object (evaluating 'firebase.initializeApp') and it points toward firebase.initializeApp(firebaseConfig);.

var firebase
let firebaseConfig = {
    apiKey: "removed",
    authDomain: "removed",
    projectId: "removed",
    storageBucket: "removed",
    messagingSenderId: "removed",
    appId: "removed"
  };

firebase.initializeApp(firebaseConfig);
let db = firebase.firestore();

Upvotes: 0

Views: 302

Answers (1)

Chris
Chris

Reputation: 959

firebase.initializeApp is the v8 (and below) way of initializing the app. You could consider using the v9 (and above) style like this:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js";
const firebaseConfig = {
  //...
};
const app = initializeApp(firebaseConfig);

More details on initialization upgrades to v9 here.

Or, using the Compat version (compatability with v8)

import firebase from "https://www.gstatic.com/firebasejs/9.8.4/firebase-app-compat.js"

firebase.initializeApp({ /* config */ });

Upvotes: 1

Related Questions