1

I trying to test my google firebase cloud functions on my local computer using firebase emulator:start. However the local instance of the cloud function is not being executed, instead the instance on Google Cloud gets executed.

I followed these steps for setting the emulator up: https://firebase.google.com/docs/functions/local-emulator

$ export GOOGLE_APPLICATION_CREDENTIALS='path/tofile'
$ firebase setup:emulators:firestore
$ firebase init firestore
$ export FIRESTORE_EMULATOR_HOST=localhost:8080
$ firebase emulators:start
 Starting emulators: ["functions","firestore","hosting"]
⚠  Your requested "node" version "8" doesn't match your global version "10"
✔  functions: Emulator started at http://localhost:5001
i  firestore: Logging to firestore-debug.log
✔  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
✔  hosting: Emulator started at http://localhost:5000
i  hosting: Serving hosting files from: www
✔  hosting: Local server: http://localhost:5000
i  functions: Watching "/home/borch/Documents/Ionic/myproject/functions" for Cloud Functions...
i  functions: Setting up Cloud Firestore trigger "myGCFunction"
✔  functions: Trigger "myGCFunction" has been acknowledged by the Cloud Firestore emulator.

As you can see the trigger is recognized by the cloud firestore emulator.

But the functions that gets executed every time I call myGCFunction is the one on Google Cloud. I think it should execute the function from my local API running at localhost:8080, correct?

I realize that only the function on the cloud is executed because I checked the firebase function console with new records of that function execution.

I updated firebase-admin and firebase-functions to its latest version:

$ cat functions/package.json | grep firebase-
    "firebase-admin": "^8.2.0",
    "firebase-functions": "^3.0.2",

Thanks.

2
  • how are you triggering the myGCFunction function? Commented Jun 29, 2019 at 6:40
  • I am using my local hosting provided by the emulator at URL localhost:5000 myGCFunction gets triggered when there is a new document on Firestore. Commented Jun 29, 2019 at 16:27

1 Answer 1

1

The local emulator is not going to respond to changes in the cloud. You have to actually change the locally emulated database in order to trigger locally emulated functions.

(Imagine if you accidentally started a local emulator that responded to changes against a busy production database - that would not scale well on your local machine, would it? The local environment must be totally isolated from any cloud hosted environment in order to work sanely.)

Sign up to request clarification or add additional context in comments.

4 Comments

Hi @Doug, if I left the emulator running on the background and if I make changes on the function index.ts file I see the changes are detected:
functions/src/index.ts changed, reloading triggers [debug] [2019-06-29T16:30:23.377Z] Functions runtime initialized. [debug] [2019-06-29T16:30:23.378Z] Disabled runtime features: undefined [debug] [2019-06-29T16:30:23.513Z] Found google-gax at /home/borch/Documents/Ionic/aws-iot-mqtt-client/functions/node_modules/google-gax/build/src/index.js [debug] [2019-06-29T16:30:23.513Z] Outgoing network have been stubbed. [debug] [2019-06-29T16:30:23.544Z] Checked functions.config() [debug] [2019-06-29T16:30:23.546Z] firebase-admin has been stubbed
do you have more info on how to completely isolate the emulated environment? I found this from google: firebase.google.com/docs/functions/local-emulator but it just refers to cloud functions on local environment.
you should mention region in both initialization and calling, otherwise, it will call default us-central and you will get an error FirebaseFunctions.instanceFor(region: 'europe-west2').useFunctionsEmulator('localhost', 5001); await FirebaseFunctions.instanceFor(region: 'europe-west2').httpsCallable('testFun3').call();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.