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.

Firebase emulator return empty data whereas working fine after deploying

See original GitHub issue

firebase-tools: 8.1.1

Platform: Ubuntu

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

I am not sure how I ran into this problem. I just followed the doc to run and debug the functions on emulator. After “firebase init”, I selected the firestore, functions and datastore emulators and all the dependencies were successfully installed. Later I started the emulator and it’s start the firestore, functions and datastore emulators on different port. Then I tried to execute my function and got no data in response.

export const activeServices = functions.https.onRequest((request, response) => {
    let services = new Array<string>();
    admin.firestore().collection(newServices).get()
    .then(serviceSnapshot => {
        serviceSnapshot.docs.forEach(doc => {
            if(doc.data().service_active){
                services.push(doc.data().service_name)
            }
        })
        const successResponse = common.success("success", 200, "Services retrieved", services)
        response.send(successResponse)
    })
    .catch(error => {
        const errorResponse = common.error("fail", 500, "Failed to get active services")
        console.error(errorResponse)
        response.send(errorResponse)
    })
})

I tried to execute this and it return nothing and executed the same functions after deploying. And I got the response. I think running only functions will try to communicate with production database. firebase emulators:start --only functions

functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠  External network resource requested!
   - URL: "http://xxx.xxx.xxx.xxx/computeMetadata/v1/instance"
 - Be careful, this may be a production service.
⚠  External network resource requested!
   - URL: "http://metadata.google.internal./computeMetadata/v1/instance"
 - Be careful, this may be a production service.

This looks like it’s trying to communicate to production but couldn’t make any successful request.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
NandhaGopiFrostcommented, Feb 7, 2021

Even am facing the same issue

  1. I have manually entered data using emulator UI, when I try to get the data back, exists is false always for me

My firestore emulator run on localhost:5000

db.collection("myfirstcollection").doc("dataexitsinthedocument").get() .then(snapShot=>{ if(snapShot.exists){ console.log(snapShot.data()) }else{ console.log("no data to fetch") } }) .catch(error=>{console.log(error);console.log(error)}) .finally(()=>{ console.log("exit on final") })

I have connected to my firestore using `if (window.location.hostname === “localhost”) {

db.useEmulator("localhost", 5000);

console.log("using emulator")

}`

0reactions
samtsterncommented, Aug 17, 2020

@Tzahile I don’t quite understand the situation you’re describing but here’s how it works:

  • If you are running both the Cloud Functions emulator and the Realtime Database emulator then:
    • Writes to the RTDB emulator will trigger cloud functions in the functions emulator
    • Reads and writes from functions using firebase-admin will use data from the RTDB emulator
  • If you are running only the Cloud Functions emulator
    • Your RTDB functions will never fire
    • Reads and writes from functions using firebase-admin will use data from production
Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase emulator return empty data whereas working fine ...
Try this: run Firebase:emulators start --only functions so that the database in use is your production database. (Obviously do so with caution ...
Read more >
Firebase emulator return empty data whereas working fine ...
After "firebase init", I selected the firestore, functions and datastore emulators and all the dependencies were successfully installed. Later I ...
Read more >
Connect your app to the Cloud Firestore Emulator - Firebase
Define a baseline set of data to use in your unit tests or continuous integration workflows, then export it to be shared among...
Read more >
The Full Guide on how to use the Firebase Emulator for the Web
First, we'll go through the process of installing the emulator and the different APIs we'll use, like, Authentication, Firestore, and Functions. Second, we'll ......
Read more >
Cloud functions for Firebase - Complete Tutorial ... - YouTube
We will also use the firebase emulator to test our functions. We will handle all kinds of cloud function triggers: #Https trigger Firebase...
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