Firestore/Firebase Emulator Not Running
Asked Answered
J

10

42

I'm trying to test my functions locally using the guide listed here https://firebase.google.com/docs/functions/local-emulator

I have installed the latest firebase-tools using

npm install -g firebase-tools

In my package.json I confirmed to be running

"firebase-admin": "^7.3.0",
"firebase-functions": "^2.3.1",

When I try to run my functions using

firebase emulators:start

It gives me the below output. What am I doing wrong?

Starting emulators: ["functions"]
⚠  Your requested "node" version "8" doesn't match your global version "11"
✔  functions: Emulator started at http://localhost:5001
i  functions: Watching "[FUNCTIONS FOLDER PATH]" for Cloud Functions...
⚠  Default "firebase-admin" instance created!
⚠  Ignoring trigger "[FUNCTION NAME]" because the service "firebaseauth.googleapis.com" is not yet supported.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.

etc.
etc.
etc.
i  functions: HTTP trigger initialized at http://localhost:5001/[APP NAME]/us-central1/[FUNCTION NAME]

[2019-05-15T21:43:52.436Z]  @firebase/database: FIREBASE WARNING:  
{"code":"app/invalid-credential","message":"Credential implementation provided to   
initializeApp() via the \"credential\" property failed to fetch a valid Google  
OAuth2 access token with the following error: \"Error fetching access token: Error  
while making request: getaddrinfo ENOTFOUND metadata.google.internal  
metadata.google.internal:80. Error code: ENOTFOUND\"."} 
Jolee answered 15/5, 2019 at 21:41 Comment(8)
Please limit yourself to one question per post. As it stands now, you're asking about two unrelated things. If you have reproductions steps for something that looks like a bug in the emulator, post the the project GitHub instead of Stack Overflow. github.com/firebase/firebase-toolsLindsaylindsey
Removed the "unrelated thing" even though it's part of the warning messages displayed in the output.....Jolee
And I don't know if it's a bug, that's the point of asking this question Doug. There aren't any reproduction steps except for the single command line code of firebase emulators:start, which is the only thing the guide says to do. Would be great if Firebase improved its documentation in this areaJolee
The reproduction steps would necessarily say everything one can do to get to this state, including showing any code that's being used. Preferably, the minimal amount of code that triggers the problem, so folks don't have to try to deal with more code than necessary. The engineers who made the emulator are more likely to pay attention to the GitHub issue than Stack Overflow.Lindsaylindsey
I have 37 functions that work perfectly when deploying to the cloud environment. When running locally using the above guide it all gets blown up with errors as seen above. Will try the project githubJolee
Please do. The new emulator definitely has some bugs in it. I haven't seen any of those messages, but you might want to downgrade to 6.8.0 before all the big changes were made.Lindsaylindsey
Maybe also take a look at this approach: tianhaoz.com/eng/server/firebase/emulator.html#cloud-functions and github.com/tianhaoz95/iwfp/blob/master/functions/…Nalchik
@DougStevenson My emulators are working fine. But when I send a request it returns a null data. Any idea why ? I am using firestore, functions and database emulator. I also tried my changing the rules of database.Mccollough
P
61

I had the same issue there were a few things wrong for me

  1. ensure the emulator is installed by running firebase setup:emulators:firestore

My second issue was that my initial firebase configuration had installed the config files into my home folder rather then the project folder as described [here] this meant so my project was missing firestore.rules and firestore.indexes.json and some of the configuration settings.

run firebase init to generate these files

Once I fixed these two things it worked for me. I hope this helps.

As a reference my firebase.json looks like this

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "emulators": {
    "firestore": {
      "port": "5002"
    }
  }
}
Pet answered 21/5, 2019 at 9:42 Comment(3)
Running firebase init did fix the issue. On the other hand, I had just created a new folder for functions and ran init. Weird that I had to run it again, didn't firebase know that I was using firestore and functions together initially itself? :-/Excaudate
Agree with @AswinKumarIonone
firebase init not work for me. firebase init firestore solve my problem.Wizened
M
28

If checking Firebase setup doesn't work, try this:

  • Run firebase emulators:start. Check if displayed error request to install OpenJDK.
  • If your functions interacts with Firebase APIs or Google APIs, you need to setup admin credentials. Check how to do it here: https://firebase.google.com/docs/functions/local-emulator
  • You may need to emulate functions and firestore at the same time. Use firebase emulators:start --only functions,firestore or firebase serve --only functions,firestore.
  • Keep in mind that pubsub is not suported yet. As Sam Stern comments, pub sub is now supported.
Motto answered 15/6, 2019 at 15:54 Comment(2)
Actually pubsub is supported as of the latest release (7.9.0)Doorknob
I'm getting rror: functions firestore is not a valid emulator name, valid options are: ["auth","functions","firestore","database","hosting","pubsub"] when using firebase emulators:start --only functions,firestorePerla
D
20

As of version 7.8.0 of the Firebase CLI (firebase-tools) there is a new command firebase init emulators that will help you set up all the emulators you want to run.

Doorknob answered 13/12, 2019 at 20:12 Comment(0)
N
14

Could be you don't have firestore configured properly in your firebase.json file. This makes emulator not being started.

What you need is to run firebase init firestore in your project directory. This would create firestore rules and indexes files and update your firebase.json correspondingly.

Nichrome answered 27/5, 2019 at 12:58 Comment(1)
I used firebase init database for Realtime DatabaseKellam
I
8

Actually this error comes when the user initialize the firebase project without database. So the command firebase emulators:start --only database can not start the database emulator because it need the "database.rules.json" file and the configuration entries for database in the firebase.json file . So if you forgot to initialize the database in firebase init command then you can add firebase database whenever you want by following firebase CLI command

firebase init database

then you can run firebase emulators:start --only database for starting the database emulator in the localserver .

and If you want to use emulator for both function and database then run firebase serve --only functions,database

Isaak answered 31/3, 2020 at 9:14 Comment(0)
C
5

Simple fix

  1. Check you have latest firebase-tools (8.x)
  2. Add an empty firestore configuration to firebase.json
{
  "functions": {
    ...
  },
  "firestore": {}
}

This will tell firebase-tools to initialize and run the firestore emulator.

enter image description here

Cybil answered 1/12, 2020 at 0:58 Comment(0)
S
2

Also came across this issue, I was importing data, but I was in the wrong directory, simple fix. Hope this may help someone as error output gives no indication.

Original command:

firebase emulators:start --import ./firebaseexport

Error:

i  emulators: Starting emulators: functions, firestore, hosting
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub

Error: An unexpected error has occurred.

Fix:

firebase emulators:start --import ./functions/firebaseexport
Smite answered 27/5, 2021 at 18:38 Comment(0)
P
2

In the firebase.json file Change host for firestore from

"host": "http://localhost"

(which is created during the firebase init command) to

"host": "localhost"

Doing this fixes the problem and the firestore emulator runs.

Elaboration: firebase version 9.16.0

With the firebase.json snippet

{
        // ...
        "emulators": {
          "firestore": {
            "host": "http://localhost",
            "port": "8081"
          }
        }
      }

The emulator would stop with:

firebase emulators:start --only firestore
i  emulators: Starting emulators: firestore
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
⚠  firestore: Port 8081 is not open on http://localhost, could not start Firestore Emulator.
⚠  firestore: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "firestore": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Firestore Emulator, port taken.

But when "http:localhost" is changed to "localhost", then it works (the error message is missleading)..

The key was (in debug mode) the line

port check error: Error: getaddrinfo ENOTFOUND http://localhost

one suggestion in another link was to check /etc/hosts, but a simplier fix was to get rid of the "http://" part.

Pulchritude answered 10/8, 2021 at 6:55 Comment(1)
Setting host explicitly to 127.0.0.1 workied for me. 'localhost' and 'localhost' would timeout.Injustice
L
0

For me after installing th java runtime , everything worked perfectly.

install java runtime

Lenette answered 28/3, 2021 at 17:16 Comment(1)
This is what I had to do.Illusive
U
0

I fixed it by doing

  1. firebase init

select the things you need using space key Then after finish

  1. firebase emulators:start
Upgrowth answered 27/7, 2022 at 20:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.