Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore/Firebase Emulator Not Running

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\"."} 
like image 801
siefix Avatar asked May 15 '19 21:05

siefix


People also ask

Is not open on localhost could not start firestore emulator?

This error is because of the failed quitting from firebase emulator. You already have the process of previous firebase emulator. For a new start, you have to find and stop the previous process.

How do I import firestore to emulator?

Go to my local Firebase project path. Start the emulators using: firebase emulators:start. Create manually some mockup data using the GUI at http://localhost:4000/firestore using the buttons provided: + Start Collection and + Add Document. Export this data locally using: emulators:export ./mydirectory.


Video Answer


2 Answers

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"
    }
  }
}
like image 82
Azure Avatar answered Oct 09 '22 13:10

Azure


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.
like image 26
Mario Orozco Avatar answered Oct 09 '22 12:10

Mario Orozco