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
<script type="module"> import { initializeApp } from "https://www.gstatic.com/firebasejs/9.1.0/firebase-app.js"; const firebaseConfig = { apiKey: "...", authDomain: "...", databaseURL: "...", projectId: "...", storageBucket: "...", messagingSenderId: "....", appId: "..." }; // Initialize Firebase const app = initializeApp(firebaseConfig); //below import statement is causing the error import { getDatabase, ref, set } from "firebase/database"; const db = getDatabase(); </script> <script type="text/javascript" > function InsertData() { set(ref(db, 'TheStudent/'+rollV), { NameOfStudent: "abc", RollNo: 13, Section: "B", Gender: "Male" }); } document.getElementById('insertBtn').onclick = InsertData; </script>
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:
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.1.0/firebase-database.js"; // CDN URL instead of "firebase/database"