'"No Firebase App '[DEFAULT]' has been created", but it has been created
I am following this guide, and I can't seem to access firebase properly. In the first line in app.js I can print the value without problem, but the second line gives the error Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). But it has been initialized, since I can print its contents, but but on the second line it can't find them?
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://www.gstatic.com/firebasejs/7.16.1/firebase.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.8/firebase-app.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/9.6.8/firebase-auth.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.6.8/firebase-firestore.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.8/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyD1MDRG2-93SlVo6VJcKkyeB3d-5rAoagY",
authDomain: "fir-project-c7781.firebaseapp.com",
projectId: "fir-project-c7781",
storageBucket: "fir-project-c7781.appspot.com",
messagingSenderId: "1052101364893",
appId: "1:1052101364893:web:09b992d02d2b7fb1ff5874",
measurementId: "G-YH5VQ2PYP3"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
<script src="app.js"> </script>
</head>
<body>
<h1>My awesome app</h1>
</body>
</html>
and app.js
console.log(firebase)
const auth = firebase.auth();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
