为什么我会收到 404 错误,没有 Firebase 应用'[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

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

404错误

第一条错误消息,

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

由引起

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

其中文件CCD_ 1不存在。

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.initializeApp()之前先调用firebase.auth()

<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 Hosting,所以您也可以使用内置的助手脚本自动调用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>

相关内容

最新更新