Firebase-tools: Unable to use production Firestore from local Cloud Functions emulator

Created on 7 Feb 2020  路  1Comment  路  Source: firebase/firebase-tools

[REQUIRED] Environment info


firebase-tools: 7.12.1


Platform: Windows 10

[REQUIRED] Test case

ENVIRONMENT VARIABLES

GOOGLE_APPLICATION_CREDENTIALS=

/functions/index.js

const firebase = require("firebase-admin");
firebase.initializeApp();

exports.userListener= functions.firestore.document("/users/{uid}")
.onWrite((change, context) => {
  console.log(change);
  console.log(context);
})

[REQUIRED] Steps to reproduce

Simply run firebase emulators:start --only functions

[REQUIRED] Expected behavior

I expect the userListener function to trigger when my webapp writes to /users/{uid}

[REQUIRED] Actual behavior

CONSOLE OUTPUT

i  emulators: Starting emulators: functions
+  functions: Using node@8 from host.
+  functions: Emulator started at http://localhost:5001
i  functions: Watching "<path>\functions" for Cloud Functions...
!  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to <service-account.json>. Non-emulated services will access production using these credentials. Be careful!
i  functions[userListener]: function ignored because the firestore emulator does not exist or is not running.
+  All emulators started, it is now safe to connect.

The console tells me non-emulated services will use the app credentials provided, then immediately tells me off for not emulating a service it has credentials for.

Am I being an idiot? I feel like I'm doing everything right but clearly something is amiss.

emulator-suite question

>All comments

@tupto hey sorry for the confusion but that's not possible and it's not something that will ever be possible.

The local emulator can read/write data from production services (using the Admin SDK) but you can't trigger local functions based on production events. Those events never leave Google's private network so there's no way to subscribe to them on your machine.

If you want to test your firestore functions locally you can run both emulators together (firestore and functions). Then when you write to the firestore emulator locally (using a test script or another function), it will trigger local functions.

Was this page helpful?
0 / 5 - 0 ratings