为什么会出现404错误,并且Firebase应用程序'[DEFAULT]'没有什么意思?

问题描述 投票:0回答:1

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

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
javascript firebase firebase-hosting
1个回答
0
投票

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

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).

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

在您的代码中,您尝试先在此处调用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>

这些步骤在Getting Started documentation中有详细记录。

因为您正在使用Firebase Hosting,所以您还可以使用内置的帮助程序脚本自动调用项目所需的配置来调用initializeApp()(您可以see here):

<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>
© www.soinside.com 2019 - 2024. All rights reserved.