首页 > 解决方案 > 为什么我会收到 404 错误,没有 Firebase App '[DEFAULT]' 是什么意思?

问题描述

它到底是什么意思,我该如何解决?

Failed to load resource: the server responded with a status of 404 ()
firebaseNamespaceCore.ts:106 Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase
App.initializeApp() (app/no-app).
     at f (https://www.gstatic.com/firebasejs/7.9.1/firebase.js:1:73499)
     at Object.i [as auth] (https://www.gstatic.com/firebasejs/7.9.1/firebase.js:1:73757)
     at https://superx-bcf15.web.app/:37:22

标签: javascriptfirebasefirebase-hosting

解决方案


您提供的错误消息实际上是两个单独的错误。

404 错误

第一条错误消息,

Failed to load resource: the server responded with a status of 404 ()

是由

<script src="js/app.js"></script>

文件https://superx-bcf15.web.app/js/app.js不存在的地方。

Firebase“[DEFAULT]”应用

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

此错误消息表明您firebase.initializeApp()在尝试在其他地方使用 SDK 之前没有调用传递所需的配置参数。

在您的代码中,您尝试在此处调用firebase.auth()之前调用firebase.initializeApp()

<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase.js"></script>
<script>
    firebase.auth().onAuthStateChanged(function(user){
        if(user){
            window.location.href = "admin.html";
        }
    });
</script>

您需要将其更改为

<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase.js"></script>
<script>
    firebase.initializeApp(/* your firebase config here */);
    firebase.auth().onAuthStateChanged(function(user){
        if(user){
            window.location.href = "admin.html";
        }
    });
</script>

这些步骤在入门文档中有详细记录。

因为您使用的是 Firebase 托管,所以您还可以使用内置帮助脚本自动调用initializeApp()项目所需的配置(如您在此处看到的):

<script src="https://www.gstatic.com/firebasejs/7.9.1/firebase.js"></script>
<script src="/__/firebase/init.js"></script>
<script>
    firebase.auth().onAuthStateChanged(function(user){
        if(user){
            window.location.href = "admin.html";
        }
    });
</script>

推荐阅读