2

I am trying to test a Firebase cloud function on an emulator with real production firestore. When I start up my functions emulator, I get an error i functions[sendPushOnNewMessage]:function ignored because the firestore emulator does not exist or is not running. Interestingly, I can read from firestore (from production data), but firebase emulator refuses to allow these functions to start.

❯ firebase emulators:start --only functions
i  emulators: Starting emulators: functions
i  ui: Emulator UI logging to ui-debug.log
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/.../functions/3afae-a81e699d1cf0.json. Non-emulated services will access production using these credentials. Be careful!
⚠  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
>  Starting up...
i  functions[createUserRecord]: function ignored because the auth emulator does not exist or is not running.
i  functions[sendPushOnNewMessage]: function ignored because the firestore emulator does not exist or is not running.

Here is how I am using service account to setup (I know this works since I can read documents):

// Service account initialization.
let serviceAccount = require('./3afae-a81e699d1cf0.json');
var initOptions = {}
emulator#set_up_admin_credentials_optional.
if (process.env.FUNCTIONS_EMULATOR) {
  initOptions.credential = admin.credential.cert(serviceAccount)
}
admin.initializeApp(initOptions);
const firestore = admin.firestore();

Example of my trigger function:

exports.sendPushOnNewMessage = functions.firestore.document('chats/{chatID}/messages/{messageID}').onCreate((change, context) => {
    console.log("Trigger called")
}
3
  • Does this answer your question? How does Firebase Firestore emulator work?
    – sllopis
    Jun 8, 2020 at 12:44
  • I guess the reason why I was still confused by that answer is that if you don't setup firestore emulator, you can still access production (read data for example). Also, the CLIT warns ⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
    – Zorayr
    Jun 8, 2020 at 18:49
  • 2
    That's correct. By using firebase emulators:start --only functions, you are just starting the emulator for functions that don't include Firestore. If you would like to run the Firebase emulator for multiple products (Functions and Firestore) just run firebase emulators:start. More information can be found in the documentation.
    – sllopis
    Jun 9, 2020 at 8:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy