functions-samples: Ignoring trigger because the Cloud Firestore emulator is not running (firebase serve)

How to reproduce these conditions

Sample name or URL where you found the bug https://github.com/firebase/functions-samples/tree/master/stripe

Failing Function code used (including require/import commands at the top) ‘use strict’;

const functions = require(‘firebase-functions’); const admin = require(‘firebase-admin’); admin.initializeApp(); const logging = require(‘@google-cloud/logging’)(); const stripe = require(‘stripe’)(functions.config().stripe.token); const currency = functions.config().stripe.currency || ‘USD’;

// [START chargecustomer] // Charge the Stripe customer whenever an amount is written to the Realtime database exports.createStripeCharge = functions.firestore.document(‘stripe_customers/{userId}/charges/{id}’).onCreate(async (snap, context) => { const val = snap.data(); try { // Look up the Stripe customer id written in createStripeCustomer const snapshot = await admin.firestore().collection(stripe_customers).doc(context.params.userId).get() const snapval = snapshot.data(); const customer = snapval.customer_id // Create a charge using the pushId as the idempotency key // protecting against double charges const amount = val.amount; const idempotencyKey = context.params.id; const charge = {amount, currency, customer}; if (val.source !== null) { charge.source = val.source; } const response = await stripe.charges.create(charge, {idempotency_key: idempotencyKey}); // If the result is successful, write it back to the database return snap.ref.set(response, { merge: true }); } catch(error) { // We want to capture errors and render them in a user-friendly way, while // still logging an exception with StackDriver console.log(error); await snap.ref.set({error: userFacingMessage(error)}, { merge: true }); return reportError(error, {user: context.params.userId}); } }); // [END chargecustomer]]

// When a user is created, register them with Stripe exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => { const customer = await stripe.customers.create({email: user.email}); return admin.firestore().collection(‘stripe_customers’).doc(user.uid).set({customer_id: customer.id}); });

// Add a payment source (card) for a user by writing a stripe payment source token to Realtime database exports.addPaymentSource = functions.firestore.document(‘/stripe_customers/{userId}/tokens/{pushId}’).onCreate(async (snap, context) => { const source = snap.data(); const token = source.token; if (source === null){ return null; }

try { const snapshot = await admin.firestore().collection(‘stripe_customers’).doc(context.params.userId).get(); const customer = snapshot.data().customer_id; const response = await stripe.customers.createSource(customer, {source: token}); return admin.firestore().collection(‘stripe_customers’).doc(context.params.userId).collection(“sources”).doc(response.fingerprint).set(response, {merge: true}); } catch (error) { await snap.ref.set({‘error’:userFacingMessage(error)},{merge:true}); return reportError(error, {user: context.params.userId}); } });

// When a user deletes their account, clean up after them exports.cleanupUser = functions.auth.user().onDelete(async (user) => { const snapshot = await admin.firestore().collection(‘stripe_customers’).doc(user.uid).get(); const customer = snapshot.data(); await stripe.customers.del(customer.customer_id); return admin.firestore().collection(‘stripe_customers’).doc(user.uid).delete(); });

// To keep on top of errors, we should raise a verbose error report with Stackdriver rather // than simply relying on console.error. This will calculate users affected + send you email // alerts, if you’ve opted into receiving them. // [START reporterror] function reportError(err, context = {}) { // This is the name of the StackDriver log stream that will receive the log // entry. This name can be any valid log stream name, but must contain “err” // in order for the error to be picked up by StackDriver Error Reporting. const logName = ‘errors’; const log = logging.log(logName);

// https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/MonitoredResource const metadata = { resource: { type: ‘cloud_function’, labels: {function_name: process.env.FUNCTION_NAME}, }, };

// https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorEvent const errorEvent = { message: err.stack, serviceContext: { service: process.env.FUNCTION_NAME, resourceType: ‘cloud_function’, }, context: context, };

// Write the error log entry return new Promise((resolve, reject) => { log.write(log.entry(metadata, errorEvent), (error) => { if (error) { return reject(error); } return resolve(); }); }); } // [END reporterror]

// Sanitize the error message for the user function userFacingMessage(error) { return error.type ? error.message : ‘An error occurred, developers have been alerted’; } Steps to set up and reproduce Windows 10, brand new installation of node 10 and firebase-tools (v 6.9.2). Follow the instructions on the github page for installing the npm package and setting up stripe key and so on, but instead of firebase deploy, I used firebase serve. Change node version to 10 in package.json. Attached stripe example to firebase hosting as well.

Sample data pasted or attached as JSON (not an image)

Security rules used

Debug output

Errors in the console logs functions: Using node@10 from host.

  • functions: Emulator started at http://localhost:5001 i functions: Watching “<functions repo>” for Cloud Functions… i hosting: Serving hosting files from: public
  • hosting: Local server: http://localhost:5000 ! Default “firebase-admin” instance created! ! Ignoring trigger “createStripeCharge” because the Cloud Firestore emulator is not running. ! Ignoring trigger “createStripeCustomer” because the Cloud Firestore emulator is not running. ! Ignoring trigger “addPaymentSource” because the Cloud Firestore emulator is not running. ! Ignoring trigger “cleanupUser” because the service “firebaseauth.googleapis.com” is not yet supported.

(node:23520) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead

Screenshots

Expected behavior

The local emulator starts running and I can test firebase functions without deploying them.

Actual behavior

Firebase hosting works fine, but all cloud firestore functions get ignored.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 7
  • Comments: 57

Most upvoted comments

I changed the serve script in my functions package.json to npm run build && firebase serve --only functions,firestore and it recognizes both my HTTP triggers and Cloud Firestore Triggers.


Edit: Moving my other comment here for visibility with this issue

So this isn’t working like I thought.

Running serve ("serve": "npm run build && firebase serve --only functions") I get the following message for any Firestore triggers:

Ignoring trigger “ordersCreate” because the Cloud Firestore emulator is not running.

Switching the serve command to npm run build && firebase serve --only functions,firestore I get the following message for any Firestore triggers:

Trigger “ordersCreate” has been acknowledged by the Cloud Firestore emulator.

The emulator now works, but…

Unfortunately, this still means the triggers aren’t initialized so I can’t test them locally and see any console logs or other debugging information.

@AndersonHappens could be you don’t have firestore configured properly in your firebase.json file. This makes emulator not being started.

What you need is to run firebase init firestore in your project directory. This would create firestore rules and indexes files and update your firebase.json correspondingly.

this bug is ruining my life. it makes testing database sharding almost impossible.

Same problem. Tried using firebase emulators:start to start hosting, firestore, functions. The idea was same op, to test triggers on a database. Also tried with firebase serve no go. Same error in all, updates the actual database and even though it reports as “acknowledged” by emulator the functions does not trigger “onCreate” and so on…

functions package:
  "firebase-admin": "^8.0.0",
  "firebase-functions": "^3.0.0",
  "glob": "^7.1.4"

mainproject:
  "firebase": "^6.2.0",

$ firebase --version
7.0.0

All emulators start for me, however I receive this message for my auth onCreate trigger:

functions[auth_onCreate-default]: function ignored because the firebaseauth.googleapis.com emulator does not exist or is not running.

This is killing me slowly. Fixed it a couple of days ago, and bam, same error again?! Cannot seem to work out why.

Had similar problem with firestore emulator. Was resolved after I run

firebase init

again, selecting database and functions. Maybe same will help for other types of emulators.

Same here, I can’t my triggers to work locally via the emulators.

For anyone struggling with testing firestore triggers, I’ve made an example repository that will hopefully help other people

https://github.com/benwinding/example-jest-firestore-triggers

I just spent 4 hours trying to resolve this issue. Ended up shotgunning the onCreate event straight to production after trying everything I found here and on stackoverflow. I’m still getting the error: functions[createUserDoc]: function ignored because the firebaseauth.googleapis.com emulator does not exist or is not running.

I had the same issue. I was using a randomly generated project ID when running unit tests (as suggested in a Firecast I think?). Except this was causing writes not to go the emulator and were just lost. MAKE SURE THE PROJECT ID OF YOUR CLIENT MATCHES THAT OF THE EMULATOR.

Edit: I now realise that setting a project ID that differs from your actual Firebase project ID disable the triggers on purpose - it in essence is making writes to a different database that your triggers are not subscribed to. This is great for rules testing, but this is a key fact to be aware of!

I totally forgot to build the project after I edited it so it kept running the old code. When I run npm run build, it worked.

I overcame this by running firebase init emulators

Found it from here: https://github.com/firebase/firebase-tools/pull/1755

This is how I got mine working for firestore emulator … reference for future project …

  1. I added these to windows environment variables

FIRESTORE_EMULATOR_HOST = localhost:8080 FIREBASE_FIRESTORE_EMULATOR_ADDRESS = localhost:8080

  1. I’m using vuejs … in the main.js file I have this code after firebase.initializeApp

if (window.location.host.includes(“localhost”) || window.location.host.includes(“127.0.0.1”) || process.env.NODE_ENV === “development”) { firebase.functions().useFunctionsEmulator(“http://localhost:5001”); firebase.firestore().settings({ host: “localhost:8080”, ssl: false, }); }

  1. Your project mush have installed firebase functions, firestore, emulators, etc … you have to search on how to do it … then I have this code in the index.js of functions folder

const funcName = functions.firestore.document(“users/{userId}”).onWrite((change, context) => { console.log(“USERID:”, context.params.userId); return true; });

  1. in the client side … my method calls like this

firebase .firestore().collection(“users”).doc(user.uid) .set( {name: this.profile.name, }, { merge: true });

  1. to start the emulator for firestore, it must be

firebase emulators:start --only firestore,functions

  1. in firebase.json i have this entry

    “emulators”: { “functions”: { “port”: 5001 }, “firestore”: { “port”: 8080, “host”: “localhost” }, “hosting”: { “port”: 5000 } },

  2. you need to restart the emulator from time to time, especially when you think you’re doing the right thing but the result is not

NEED TO MAKE THIS WORK: function ignored because the auth emulator does not exist or is not running.

First you need to download the emulator: firebase setup:emulators:firestore and then run the functions locally withfirebase serve --only functions,firestore

I also spent the whole day trying to get trigger work, or just get rid of the “because the firebaseauth.googleapis.com emulator does…”.

@Galzk you can also git-clone, edit, and deploy your project from the Google Cloud Shell of your Firebase account: https://ssh.cloud.google.com/cloudshell/editor

Guys this is my first major firebase project and I’m kinda stuck, same issue, deploying functions takes forever and this was my only sane option 😕 Is the only solution is dual booting Linux or getting a mac? I really like the tech but the dev experience I’m getting is not smooth at all…

@danieldanielecki did you test the firestore functions for firebase serve --only functions,firestore and see if they printed to your local console? Did you test to see if it was running your local code (and not your deployed code)? Because for me it only ever runs the deployed code and not the local code I’m trying to serve

firebase serve did not work, firebase serve --only functions,firestore did work for me on Node 10.

"firebase": "^6.3.1",
"firebase-admin": "^8.3.0",
"firebase-functions": "^3.0.2"