我已经按照指南 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/