javascript - 为什么我会收到 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
解决方案
您提供的错误消息实际上是两个单独的错误。
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>
推荐阅读
- java - 尝试获取列表类型的 API 响应时响应为空
- javascript - 用随机长度组jquery按字符拆分单词
- ios - Flutter 运行 - 无法构建 iOS 应用程序 - 命令 PhaseScriptExecution 失败,退出代码为非零
- javascript - 了解D3中的调用方法
- docker - 使用 Docker 创建基于 CentOS 8 的 PHP Web 服务器
- flutter - Flutter如何为列表中的每个元素制作无状态小部件
- c++ - C++ - 块不移动,我的数组不工作
- python-3.x - 在 Pyglet 中播放音频时听不到声音(Raspberry Pi 4B,Raspbian)
- sql - 使用不同的阈值多次选择同一列,然后组合结果(在 Google Big Query 视图中)
- javascript - 为什么我的 javascript 代码在代码挑战的性能测试用例中失败?