While attempting to integrate Firebase with my Vue 4 application, I encountered the following error:
Uncaught TypeError: db__WEBPACK_IMPORTED_MODULE_1_.default.database is not a function
The versions I am using are: "firebase": "^9.0.0" "vue": "^3.0.0"
import { initializeApp } from "firebase/app";
import { getDatabase } from "firebase/database";
const firebaseConfig = {
// keys
};
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
export {db}
Here is my function call:
import {reactive} from 'vue';
import { ref, set, push } from "firebase/database";
import {db} from "./db"
export default {
setup(){
const inputUsername = ref("");
const inputMessage = ref("");
const state = reactive({
username: "",
messages:[]
});
const Login = () =>{
if(inputUsername.value != "" || inputUsername.value != null){
state.username = inputUsername.value;
inputUsername.value = "";
}
}
const SendMessage = () => {
// const messagesRef = db.database().ref("messages");
if (inputMessage.value === "" || inputMessage.value === null) {
return;
}
const message = {
username: state.username,
content: inputMessage.value
}
set(push(ref(db, 'messages')), message);
// messagesRef.push(message);
inputMessage.value = "";
}
return{
inputUsername,
Login,
state,
inputMessage,
SendMessage
}
}
}
I have attempted to resolve this issue by following the suggestions provided, but unfortunately, it did not work.
Thank you!