Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

232
Views
Have an error with Realtime Database from Firebase
    // db.js file

    import * as firebase from "firebase/app"
    import "firebase/database"
    
    const config = {
        apiKey: "" ...
    }
    
    const db = firebase.initializeApp(config)
    export default db

    // App.vue file


    import { reactive, onMounted, ref } from 'vue'
    import db from "./db.js";
    
    const SendMessage = () => {
          const messagesRef = db.database().ref("messages")
    
          if(inputMessage.value === "" || inputMessage.value === null) {
            return
          }
    
          const message = {
            username: state.username,
            content: inputMessage.value
          }
    
          messagesRef.push(message)
          inputMessage.value = ""
        }

I try to make a little chat app with Vue.js and Firebase. So i don't understand because i receive this when i try to send a message : db_js__WEBPACK_IMPORTED_MODULE_1_.default.database is not a function at Proxy.SendMessage (App.vue?3dfd:63:1)

I think it's about the import but i try to change for the V9 of firebase but that's didn't work.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firebase V9 is build in functional aproach. Im working with firestore usually give me a sign if some thing not working.

db.js

import { initializeApp } from 'firebase/app';
import { getDatabase, ref, push, child, serverTimestamp } from 'firebase/database'

const config = {
  apiKey: "" ...
}

const firebase = initializeApp(config)
const db = getDatabase()

function addMessage(path, message) {
  message.createAt = serverTimestamp() // On database side database will assign current
  // timestamp to this field so you will be able to order data
  // from newest to oldest for example.
  return push(child(ref(db, path)), message)
}
export { addMessage }

App.vue file

import { reactive, onMounted, ref } from 'vue'
import { addMessage } from "./db.js";

const SendMessage = async () => {
  if (!inputMessage.value) return 
  // line above will check are value is "" or null by throwing
  // false and using ! in front you changing it to true.

  const message = {
    username: state.username,
    content: inputMessage.value
  }

  const result = await addMessage('path to data in tree', message)
  // async/await will await until data is saved in database and then will do code bellow.
  console.log(result.key) // If you await you can read result if result is not void.
  inputMessage.value = ""
}

If you use ref() in .vue files make database operations outside of vue files database have same ref() function but they work different. You can allso change name of one function in import line import { ref as dbRef } from 'firebase/database'

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!