VueJS - Vuefire - Unexpected Error: document.onSnapshot is not a valid function

I'm currently working on integrating Vuefire into my project. I have been following the instructions provided on the Vuefire website, but I am encountering an error.

db.js:

import firebase from 'firebase/app'
import 'firebase/firestore';
const firebaseConfig = {
apiKey: ....,
authDomain: ....,
projectId: ....,
storageBucket: ...,
messagingSenderId:....,
appId: ..."
};
const app = firebase.initializeApp(firebaseConfig)
export const db = app.firestore()

main.js

    import Vue from 'vue';
import App from './App.vue';
import vuetify from './plugins/vuetify';
import { firestorePlugin } from 'vuefire'
import DatetimePicker from 'vuetify-datetime-picker';
Vue.use(firestorePlugin)
Vue.config.productionTip = false;
Vue.use(DatetimePicker)
new Vue({
vuetify,
render: h => h(App)
}).$mount('#app');

App.vue

import { db } from "../db";
export default {
name: "App",
data() {
return {
fireDB: [],
  },
mounted() {

console.log(this.fireDB);
  },
firestore: {
// fireDB: db.collection("something").doc('else').get().then((res) => {
//   console.log(res);
// }) - encounter an error when using this approach.

//fireDB: db.collection("something") - generates an array with an object representing the database when used.
  },

};

The console suggests that the 'document' where onSnapshot is invoked is a promise.

Answer №1

While troubleshooting, I encountered a similar error with VuexFire that was caused by using Firebase v9, which has a different API not yet compatible with Vuefire.

To address this issue, you have two options: either switch to the new Firebase v9 API or downgrade to v8, as suggested in the current Viewfire documentation (although labeled as v7).

To perform the downgrade, review your package.json to ensure Firebase is set to v8 e.g.

"firebase": "^8.10",
(and then run npm i)

For reference, here is the query syntax for v8: https://firebase.google.com/docs/firestore/quickstart#web-version-8_4

db.collection("users").get().then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
        console.log(`${doc.id} => ${doc.data()}`);
    });
});

And here is the syntax for v9: https://firebase.google.com/docs/firestore/quickstart#web-version-9_4

const querySnapshot = await getDocs(collection(db, "users"));
querySnapshot.forEach((doc) => {
  console.log(`${doc.id} => ${doc.data()}`);
});

I managed to resolve issues with VuexFire v3.2.5 by downgrading to Firebase v8 and adjusting my data bindings according to the old syntax recommended in Viewfire's documentation.

An ongoing issue regarding the upgrade process can be found on the Viewfire GitHub page: https://github.com/vuejs/vuefire/issues/1128

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Visualizing Data with d3.js Force Chart: Integrating Images with Nodes for Dynamic Animation

After enhancing a force diagram to compare two profiles, I am faced with the challenge of getting the main node to display an image. View comparison here How can I centrally align and size the image correctly while making the thumbnail data from the JSO ...

Selecting options using AngularJS to parse through a list

I am faced with a challenge involving a collection of strings representing years. Here is an example: $scope.years = ["2001", "2002", "2003", ...]; My goal is to display these values in a select tag within a web page. However, whenever I attempt this usi ...

Calculate the length of a JSON array by using the value of one of its

What is the most efficient way to obtain the length of a JSON array in jQuery, based on the value of its attribute? As an illustration, consider the following array: var arr = [{ "name":"amit", "online":true },{ "name":"rohit", "online":f ...

What is the best way to bundle an Express server into an Electron application?

Currently in the process of developing an Electron app using vue-cli-electron-builder. My setup includes a local MySQL database and an Express server. I am wondering how to bundle my Express server with the Electron app? The Express server is used for d ...

Troubleshooting the "@material-ui/core" issue in React: Step-by-step guide

Issue with React: Unable to locate the '@material-ui/core' module in 'C:\Users\user\Downloads\inTech'22-Web Development (EDUGEN)\edu-gen\src\components' Resolution Command: To resolve, run npm in ...

The select event in Vuetify's v-select component does not fire when clicking on an option with a custom

Currently, I am utilizing the beta version of Vuetify (v3.0.0-beta.6) due to the necessity of using Vue 3 which is not compatible with Vuetify 2.x. My objective is to create an i18n selector featuring country flag icons. For managing i18n functionalities ...

Exploring the movement from one component to another in React Native

When working with React Native, I encountered a challenge in navigating between two views. The issue arises from having the button to navigate on one component while my main component is elsewhere. I am using react-navigation for this purpose. Here's ...

Error 404 encountered while attempting to use the POST method in Node.js

In my latest project, I successfully created an index.js file that sends SMS messages based on input from Postman. The code, which I've included below with obscured API key and secret for privacy, is functioning as expected: const express = require(& ...

What is the process for acquiring a comprehensive catalog of Node.js modules?

Currently, I am working on integrating NPM functionality into my Node.js applications. My goal is to be able to analyze the node modules available on my system. When referring to a "module" in this context, it could either be an identifier like "fd" or a f ...

Looking to retrieve the dynamic "Publish Date" value from a webpage using HtmlUnit in Java?

As part of a coding exercise, I am currently working on a project that involves comparing the current system date with dates on various web pages to determine if there are any new updates. While most of the pages work as expected, there is one particular p ...

The AppBar in a secondary color is looking sleek and modern with the Select component

I am currently utilizing version 33 of material-ui-next: import * as mui from 'material-ui'; Within a component, I have an AppBar featuring a ToolBar and a Select: render() { return ( <mui.AppBar color="secondary"> <mui.To ...

Exploring the differences between using Node.js JSON.parse during object creation versus when utilizing a getter property

This topic primarily focuses on seeking feedback on whether the current approach is optimal or if there are better ways to handle it. If you have any advice or comments on the content below, even if not directly asked for, please feel free to share. In my ...

Changing or toggling the visibility of links once the week is finished

I have a total of 4 links available, but I want to display only one link at a time, highlighting a different lunch option every week. Once all 4 weeks have passed, the first lunch menu will be shown again, starting from Monday. <div class="wrapper& ...

Utilizing Three.js to apply a matrix transformation to a collection of objects and subsequently refreshing their positions

How can we ensure that objects added to a group in a scene (now Object3D()) correctly apply the group's matrix, updating their locations within the scene? ...

Sending Parameters to an Event Listener Function

I am working on developing a basic calculator application. I have set three objectives for myself: Add an event listener to the buttons. Trigger an event when a button is clicked. Utilize the eventListener function to show the value of the clicked butt ...

How come my request from Postman to the Adonisjs API is successful, while I encounter a CORS error when trying to call the same API from the fetch() method in

I'm encountering a CORS error while attempting to log in from my Vue 3 / Ionic application in the browser, and I can't seem to pinpoint the cause. Curiously, my login request works flawlessly when using Postman. Here is an example of how my fetc ...

Refreshing CommonJS modules by reloading or reinitializing them

It is well known that CommonJS modules are designed to load only once. Imagine we have a Single Page application with hash-based navigation; when we go back to a page that has already been loaded, the code does not run again because it has already been loa ...

Is it possible to verify if each input is unique using the parsley validator?

As a novice, I am struggling with a task where I have 6 School Children IDs. The teacher needs to input these IDs, and while it's not vital for him to enter all of them, he must input at least one. Furthermore, if he decides to input more than one ID, ...

What is the best way to transform an array of strings into a JSON object?

When navigating back to a list page, I want to make sure that the filter criteria are still retained. My solution involves using cookies, which are set when the form filter is submitted. In the list page's mounted hook, I retrieve the specific cookie ...

Transform an HTML table string into JSON format

I discovered a useful library called table to JSON that allows me to convert an HTML Table to JSON using its ID (#testtable in the example below): var table = $('#testtable').tableToJSON(); alert(JSON.stringify(table)); However, I am interested ...