error that i’m getting:
Uncaught TypeError: Failed to resolve module specifier “firebase/database”. Relative references must start with either “/”, “./”, or “../”.
i am trying to setup firebase configuration for the latest version of firebase 9.1
JavaScript
x
38
38
1
<script type="module">
2
3
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.1.0/firebase-app.js";
4
5
const firebaseConfig = {
6
apiKey: "...",
7
authDomain: "...",
8
databaseURL: "...",
9
projectId: "...",
10
storageBucket: "...",
11
messagingSenderId: "....",
12
appId: "..."
13
};
14
15
// Initialize Firebase
16
const app = initializeApp(firebaseConfig);
17
18
//below import statement is causing the error
19
import { getDatabase, ref, set } from "firebase/database";
20
21
const db = getDatabase();
22
23
</script>
24
25
<script type="text/javascript" >
26
27
function InsertData() {
28
set(ref(db, 'TheStudent/'+rollV), {
29
NameOfStudent: "abc",
30
RollNo: 13,
31
Section: "B",
32
Gender: "Male"
33
});
34
}
35
36
document.getElementById('insertBtn').onclick = InsertData;
37
</script>
38
PS. i have hidden the config on purpose, so thats not the problem.
Advertisement
Answer
It seems you are using Firebase SDK over CDN so try importing database in same way:
JavaScript
1
3
1
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.1.0/firebase-database.js";
2
// CDN URL instead of "firebase/database"
3