Uncaught TypeError: Cannot read property 'collection' of undefined

Всем Привет! Я сейчас эксперементирую с FireBase, вот мой код:

<!DOCTYPE html>
<html lang="ru" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <!-- Скрипты -->
    <script src="/__/firebase/7.14.2/firebase-app.js"></script>
    <script src="/__/firebase/7.14.2/firebase-analytics.js"></script>
    <script src="/__/firebase/7.14.2/firebase-auth.js"></script>
    <script src="/__/firebase/7.14.2/firebase-firestore.js"></script>
    <script src="/__/firebase/init.js"></script>
    <!-- /Скрипты -->
    <script>
      if (firebase.apps.length === 0) {
        const firebaseConfig = {
          apiKey: "xxxxxx",
          authDomain: "xxxxxx",
          databaseURL: "xxxxxx",
          projectId: "xxxxxx",
          storageBucket: "xxxxxx",
          messagingSenderId: "xxxxxx",
          appId: "xxxxxx",
          measurementId: "xxxxxx"
        };

        firebase.initializeApp(firebaseConfig);

        var db = firebase.firestore();
      }
    // Add a new document in collection "cities"
    db.collection("cities").doc("LA").set({
        name: "Los Angeles",
        state: "CA",
        country: "USA"
    })
    .then(function() {
        console.log("Document successfully written!");
    })
    .catch(function(error) {
        console.error("Error writing document: ", error);
    });
  </script>
  </body>
</html>

К сожалению, у меня возникает такая ошибка:

firestore.html:33 Uncaught TypeError: Cannot read property 'collection' of firestore.html:33 undefined
    at firestore.html:33

Спасибо всем кто пытаеться помочь!


Ответы (0 шт):