【问题标题】:Uncaught TypeError: firebase.firestore is not a function [duplicate]未捕获的类型错误:firebase.firestore 不是函数 [重复]
【发布时间】:2020-10-28 07:07:31
【问题描述】:

我想将 firebase firestore 添加到我的 Web 应用程序中,所以我使用了这段代码

var firebaseConfig = {

  apiKey: "XXX",
  authDomain: "XXX",
  databaseURL: "XXX",
  projectId: "XXX",
  storageBucket: "XXX",
  messagingSenderId: "XXX",
  appId: "XXX",
  measurementId: "XXX",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();

var db = firebase.firestore();

但它给了我错误

 Uncaught TypeError: firebase.firestore is not a function

这是我链接到 html 的内容

<!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-app.js"></script>
    <!-- TODO: Add SDKs for Firebase products that you want to use
      https://firebase.google.com/docs/web/setup#available-libraries -->
      <script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-analytics.js"></script>
  

【问题讨论】:

    标签: javascript firebase google-cloud-firestore


    【解决方案1】:

    firebase 核心库不包含firestore 库,因此需要进行以下导入:

    import * as firebase from 'firebase';
    import 'firebase/firestore';
    

    【讨论】:

    • 它给了我这个错误 Uncaught SyntaxError: Cannot use import statement outside a module 有什么想法吗?谢谢
    • 如果你还没有使用import,你不需要为这个问题添加它。如我链接到您的问题的第二个答案所示,使用 &lt;script src="https://www.gstatic.com/firebasejs/7.15.5/firebase-firestore.js"&gt;&lt;/script&gt; 导入 Firestore SDK 可能就足够了。
    • 是的,链接
    猜你喜欢
    • 1970-01-01
    • 2015-08-18
    • 2015-11-20
    • 2016-09-13
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    相关资源
    最近更新 更多