question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I believe I have everything set up properly (following the new vuefire docs site), but I’m not getting any data read into my component from Cloud Firestore.

The server compiles and runs, the page renders in the browser, there are no errors in the console, and the “No Locations are available” message is displayed based on the v-if statement checking the length of locations and finding zero. Querying individual documents either by id or with a query also returns no results.

How can I debug this to see where the problem lies? The Firestore Web SDK seems to be behaving normally when I write out to console.log from firestore.js.

Here is my component, with a query added into the newLocation element for testing purposes:

<template lang='pug'>
  div
    h3 Locations
    ul(v-if='locations.length > 0')
      li(v-for='location in locations' :key='location.id') {{location.name}}
    p(v-else) No Locations are available.
</template>
<script>

  import { db } from '@/firebase';

  export default {
    name: 'StaffingManagerLocations',
    data: function() {
      return {
        locations: [],
        newLocation: {}
      };
    },
    firebase: {
      locations: db.collection('locations'),
      newLocation: db.collection('locations').where('name', '==', 'Victoria')
    }
  }
</script>

Here is my firebase.js file (with certain strings in the config object replaced with ...):

import * as firebase from "firebase";

const config = {
  apiKey: "...",
  authDomain: "....firebaseapp.com",
  databaseURL: "https://....firebaseio.com",
  projectId: "...",
  storageBucket: "....appspot.com",
  messagingSenderId: "..."
};

// Get a Firestore instance
export const db = firebase
  .initializeApp(config)
  .firestore();

I installed vuefire@next using npm, here is the relevant section from package.json:

  "dependencies": {
    "firebase": "^5.9.2",
    "vue": "^2.6.6",
    "vue-router": "^3.0.2",
    "vuefire": "^2.0.0-alpha.21",
    "vuetify": "^1.5.5"
  },

I have installed the plugin in main.js as follows:

import Vue from 'vue';
import App from './App.vue';

import Router from './router';

import './plugins/vuetify';

import { firestorePlugin } from 'vuefire'
Vue.use(firestorePlugin)

Vue.config.productionTip = false;

new Vue({
  "router": Router,
  "render": h => h(App),
}).$mount('#app');

There are three locations in the database:

image

However, the locations array remains empty:

image

I know my Firestore config is correct as I can run this code in a standalone HTML page and see the three documents in the console:

  window.onload = function() {

    // Initialize Firebase
    var config = {
      apiKey: "...",
      authDomain: "....firebaseapp.com",
      databaseURL: "https://....firebaseio.com",
      projectId: "...",
      storageBucket: "....appspot.com",
      messagingSenderId: "..."
    };
    firebase.initializeApp(config);

    var db = firebase.firestore();

    db.collection('locations')
      .get().then(function(results){
        console.log('retrieved locations');
        results.forEach((doc) => {
          console.log(`${doc.id} => ${JSON.stringify(doc.data())}`);
        });       
      });

  }

This appears in the console a second or two after the page loads:

retrieved locations
4zMEt9s9PKIJ4WxXm63G => {"name":"Victoria"}
IK11p3uI16S4vCXg8iia => {"name":"Paddington"}
r6PGW3mf66KCw98v6Jsi => {"name":"Waterloo"}

My Database Rules are set to the “Test” setting:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pacific202commented, Apr 2, 2019

Update - calling Cloud Firestore directly in the created event works fine:

<template lang='pug'>
  div
    h3 Locations
    ul(v-if='locations.length > 0')
      li(v-for='location in locations' :key='location.id') {{JSON.stringify(location)}}
    p(v-else) No Locations are available.
</template>
<script>

  import { db } from './../../firebase';

  export default {
    name: 'StaffingManagerLocations',
    data: function() {
      return {
        locations: [],
        newLocation: {}
      };
    },
    created: function(){
      db.collection('locations').get().then((QuerySnapshot) => {
        QuerySnapshot.forEach( (QueryDocumentSnapshot) => {
          this.locations.push(QueryDocumentSnapshot.data());
        });
      });
    }
  }
</script>

image

0reactions
sath26commented, May 19, 2020

Update - calling Cloud Firestore directly in the created event works fine:

<template lang='pug'>
  div
    h3 Locations
    ul(v-if='locations.length > 0')
      li(v-for='location in locations' :key='location.id') {{JSON.stringify(location)}}
    p(v-else) No Locations are available.
</template>
<script>

  import { db } from './../../firebase';

  export default {
    name: 'StaffingManagerLocations',
    data: function() {
      return {
        locations: [],
        newLocation: {}
      };
    },
    created: function(){
      db.collection('locations').get().then((QuerySnapshot) => {
        QuerySnapshot.forEach( (QueryDocumentSnapshot) => {
          this.locations.push(QueryDocumentSnapshot.data());
        });
      });
    }
  }
</script>

image

it worked for me. i came across same problem and it hasnt been fixed yet

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Chrome: Fix "No data received" Error - Technipages
If you still receive the “No data received” error when attempting to access websites in Chrome, you may have to uninstall and reinstall...
Read more >
How to fix the "no data received" error in Google Chrome
How to fix the "no data received" error in Google Chrome · If reload has not worked, try the shortcut Ctrl-F5 which reloads...
Read more >
Google Chrome - Error 324 - No data received
No data received. Unable to load the webpage because the server sent no data. Here are some suggestions: Reload this webpage later.
Read more >
Solved: ERR_EMPTY_REPONSE - No Data Received
One of the most common errors when trying to access a website is ERR_EMPTY_RESPONSE – No Data Received. This error can happen whether...
Read more >
How to fix the 'no data received' error on Chrome - Quora
1. Check the website's SSL Certificate and make sure it is valid and up to date. · 2. Adjust your computer's date and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found