简体   繁体   English

未捕获的 ReferenceError:未定义 firebase

[英]Uncaught ReferenceError: firebase is not defined

I tried several methods but nothing works.我尝试了几种方法,但没有任何效果。 I link this:我链接这个:

<script src="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.css" />

It's config to firebase:它是 firebase 的配置:

<script type="module">
      import { initializeApp } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-app.js";
      import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-analytics.js";
      import { getFirestore } from "https://www.gstatic.com/firebasejs/9.15.0/firebase-firestore.js";
      const firebaseConfig = {
      // some config
      };

      const app = initializeApp(firebaseConfig);
            const analytics = getAnalytics(app);
            const db = getFirestore(app);
      async function getCities(db) {
        const citiesCol = collection(db, 'cities');
        const citySnapshot = await getDocs(citiesCol);
        const cityList = citySnapshot.docs.map(doc => doc.data());
        return cityList;
      }
      </script>

Config to auth:配置授权:

<script>
          var uiConfig = {
            signInSuccessUrl: 'localhost:5500',
            signInOptions: [
            {
              provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
              signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD
            }
            ],
            tosUrl: 'localhost:5500',
            privacyPolicyUrl: function() {
              window.location.assign('localhost:5500');
            }
          };
          var ui = new firebaseui.auth.AuthUI(firebase.auth());
          ui.start('#firebaseui-auth-container', uiConfig);
        </script>

Problem is Uncaught ReferenceError: firebase is not defined.问题是Uncaught ReferenceError: firebase is not defined。 For:为了:

provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,

I'm trying to connect authorization through firebase to my website.我正在尝试通过 firebase 将授权连接到我的网站。 How to fix this?如何解决这个问题? Help please.请帮助。

The "Uncaught ReferenceError: firebase is not defined" error occurs when the code is trying to use the firebase object, but the object is not defined. “Uncaught ReferenceError: firebase is not defined”错误发生在代码尝试使用 firebase 对象但未定义该对象时。 This can happen for a number of reasons, including:发生这种情况的原因有很多,包括:

  1. The Firebase JavaScript library has not been properly loaded. Firebase JavaScript 库未正确加载。 Make sure that you have included the correct script tag to load the Firebase library in your HTML file:确保您已包含正确的脚本标记以在 HTML 文件中加载 Firebase 库:
<script src="https://www.gstatic.com/firebasejs/7.21.0/firebase-app.js"></script>
  1. You might be trying to use the firebase object before the library has finished loading.您可能会在库完成加载之前尝试使用 firebase 对象。 To fix this, you can wrap your code in a function and call it after the firebase library has finished loading:要解决此问题,您可以将代码包装在一个函数中,并在 firebase 库完成加载后调用它:
window.onload = function() {
  // Your code here
};

  1. There may be a typo or other mistake in the name of the firebase object. firebase 对象的名称可能有拼写错误或其他错误。 Make sure that you are using the correct spelling and case when referring to the object.确保在引用对象时使用正确的拼写和大小写。

  2. If you are using a bundler like webpack or rollup, make sure that the Firebase library is correctly imported and available to your code.如果您使用的是 webpack 或 rollup 等捆绑器,请确保 Firebase 库已正确导入并可用于您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM