javascript - Firebase:使用预留主机 URL 时未创建 Firebase 应用程

我已经按照指南 here 设置了我的 firebase web 项目

我决定使用保留的托管 URL,因为它似乎是处理我的项目的本地、暂存和生产环境的绝佳解决方案,如 here 所述

问题是,当尝试在我的组件之一中使用 firebase 时:

firebase.auth()

出现以下错误

没有创建 Firebase 应用“[DEFAULT]”- 调用 Firebase App.initializeApp()

index.html 文件

<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-auth.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.9.3/firebase-analytics.js"></script>
    <script src="/__/firebase/init.js"></script>
  </body>

test.jsx 文件

import firebase from "firebase";

class LoginModal extends React.Component {

sendVerificationCode() {
    var phoneNumber = this.userPhoneNumber;
    console.log("sending verification code to: ", phoneNumber);
    var appVerifier = window.recaptchaVerifier;

    firebase
      .auth()
      .signInWithPhoneNumber(phoneNumber, appVerifier)
      .then(function(confirmationResult) {
        // SMS sent. Prompt user to type the code from the message, then sign the
        // user in with confirmationResult.confirm(code).
        window.confirmationResult = confirmationResult;
        console.log("confirmationResult = ", confirmationResult);
      })
      .catch(function(error) {
        // Error; SMS not sent
        console.log("error = ", error);
        // ...
      });
  }

}

调用该函数 (sendVerificationCode()) 时,应用程序崩溃并出现以下错误:

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).

此外,我在控制台中得到了这个输出(可能是相关的,但不确定......):

init.js:1 Uncaught SyntaxError: Unexpected token '<'

关于我可能遗漏的任何问题?谢谢!!

最佳答案

如果你尝试

window.firebase

您实际上会看到 firebase 实例已经初始化。

关于javascript - Firebase:使用预留主机 URL 时未创建 Firebase 应用程序 '[DEFAULT]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60503885/

相关文章:

amazon-web-services - 无效的 LambdaFunctionAssociatio

java - Hibernate NameGenerator 中带有 hql 查询的 Nullpoi

amazon-web-services - 尝试使用 moto 模拟 s3 时出现 NoSuchBu

php - html2pdf: 生成一个空白页

css - 当您将鼠标悬停在日期上时,如何在 react 日历中显示日期的一些内容

python - 如何通过 Python 使用 GeckoDriver 和 Firefox 使 Se

c# - 如何修复错误 MC1000 未知构建错误, 'Could not find type '

reactjs - 如何在@ion-phaser/react npm 包中加载图像

android - Android下载管理器如何修改更新间隔

graphql - 如何在自定义指令上触发 visitInputObject 方法?