1

When trying to use the cloud functions emulator, I get a message stating:

function ignored because the firestore emulator does not exist or is not running

I have tried mentioned here: (Firestore/Firebase Emulator Not Running).

My functions/package.json looks like this:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

Command I'm using to start the emulator:

    firebase emulators:start --only functions

This is the output I'm getting:

i  Starting emulators: ["functions"]
!  Your requested "node" version "8" doesn't match your global version "10"
+  functions: Emulator started at http://localhost:5001
i  functions: Watching "C:\Users\MyName\Documents\MyProject\functions" for Cloud Functions...
i  functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.
+  All emulators started, it is now safe to connect.

I am doing a console.log in the function but I don't see it on the port (5001).

Any help would be appreciated.

ak22
  • 158
  • 2
  • 14
  • 1
    I don't understand what the problem is. Please edit the question to show the code of the function, how you are invoking it, and explain what's not working the way you expect. – Doug Stevenson Sep 18 '19 at 16:34
  • The function itself is not relevant. Let's just say it's doing a console log. The function runs and I see the console log when it's deployed. It is trigged when I write to a database from my app that uses a firestore database. I'm trying to run the function in the emulator. I assume the log should come out on the emulator port (5001) when the function is triggered but it's not. It does get triggered because I see the log in the firebase console (just not on the emulator port). I think this is related to the "function ignored because the firestore emulator...." print. That's the problem. – ak22 Sep 18 '19 at 17:07
  • 1
    Following up, I realized one thing. Since I was only starting the functions emulator and not the firestore emulator, the print in question is referring to the firestore emulator. So I started all the emulators and now I don't see the print. So, now the question is do the updates to the firestore also need to be "emulated" updates rather than real updates in order for the "emulated" functions to get triggered? – ak22 Sep 18 '19 at 17:37

2 Answers2

3

If you want to trigger a Firestore function, you will need to make that change in the local Firestore emulator. Locally emulated functions don't respond to actual cloud-hosted databases. The emulation on all products must be local.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    Thanks. I'm slowly getting there. Until now, I'm been actually writing to the cloud hosted database. I'm not sure how to set up an emulator for the firestore database itself. I know now how to start the emulators but in my app, I have to write to the emulator rather than the actual cloud hosted database. This is something I have not found in the documentation. Thanks for your help so far. – ak22 Sep 18 '19 at 21:33
  • My answer is saying that you can't have a local emulator respond to events in the actual cloud hosted product. The local Firestore emulator is required. – Doug Stevenson Sep 18 '19 at 21:40
  • 4
    I understand. I was just saying I haven'f found a good example of this. Can you point me to an example where a local firestore emulator triggers a local firestore function? – ak22 Sep 18 '19 at 23:27
  • 3
    1) You will want to run `firebase init emulators` to set up the Firestore emulator. 2) Follow the instructions on this page (https://firebase.google.com/docs/emulator-suite/connect_and_prototype?database=Firestore) to connect your app to the Firestore emulator. 3) Any writes from your app to Firestore will go to the emulator and those will trigger emulated functions when appropriate. – Sam Stern Dec 13 '19 at 20:10
1
functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.

Maybe the 'updateFunction' is the handler function for watching a change of your firestore documents, isn't it?

So you might need to start firestore at the same time with functions.

Just execute without --only option with the firebase.json configurations

{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
  },
  "functions": {
    "source": "functions"
  },
  "emulators": {
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 5000
    },
    "ui": {
      "enabled": true,
      "host": "localhost",
      "port": 4000
    }
  }
}

And if you want to connect your server-side functions with your IDE for debugging, you need '--inspect-functions' option, or you just have to check logs in the emulator log page "http://localhost:4000/logs"

firebase emulators:start --inspect-functions
Fredric Cliver
  • 175
  • 1
  • 1
  • 9