3

I'm trying to debug my cloud firestore triggers locally using a firestore emulator. I have imported all of my data to the emulator (production data)

This is my web application config file (Client side):

import firebase from 'firebase/app';
import 'firebase/firestore';

const { NODE_ENV } = process.env;
const isDevelop = NODE_ENV === 'develop';

const productionOptions = {
  ...
  databaseURL: 'https://myproject.firebaseio.com',
  ...
}

const developOptions = {
  ...
  databaseURL: 'https://myproject-dev.firebaseio.com',
  ...
}

firebase.initializeApp(isDevelop ? developOptions : productionOptions);

const db = firebase.firestore();
const auth = firebase.auth();
const { currentUser } = auth;

if (isDevelop) {
  db.settings({
    host: 'localhost:8080',
    ssl: false
  });
  firebase.functions().useFunctionsEmulator('http://localhost:5001');
}

export {
  firebase,
  db,
  auth,
  currentUser
};

On the admin side (cloud function project) I initialize the emulator using this command:

firebase emulators:start --only functions,firestore --inspect-functions --import=./

I can see all the data in my web application. The data is coming from the emulator (I have checked that)

The problem is when I try to write something back to the emulator the request is pending forever. for example:

async function update({ field, id, params }) { 
   try {
    const collection = db.collection(field);
    await collection.doc(id).update(params) // pending forever!
   } catch(e){
     console.log(e)
   }
}

Emulator output:

i  emulators: Starting emulators: functions, firestore
✔  hub: emulator hub started at http://localhost:4400
⚠  functions: You are running the functions emulator in debug mode (port=9229). This means that functions will execute in sequence rather than in parallel.
⚠  Your requested "node" version "8" doesn't match your global version "10"
✔  functions: functions emulator started at http://localhost:5001
i  firestore: Importing data from /Users/adi/Desktop/myproject-admin/cloudFunctions/functions/2020-05-07T09:36:11_57193/2020-05-07T09:36:11_57193.overall_export_metadata
⚠  firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i  firestore: firestore emulator logging to firestore-debug.log
✔  firestore: firestore emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  functions: Watching "/Users/adi/Desktop/myproject-admin/cloudFunctions/functions" for Cloud Functions...
>  Debugger listening on ws://localhost:9229/af9a2bd6-e5b0-4fa0-8103-53fab69a2a45
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to ./src/utils/serviceAccountKeyDevelop.json. Non-emulated services will access production using these credentials. Be careful!
>  (node:12364) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
✔  functions[api]: http function initialized (http://localhost:5001/myproject-dev/us-central1/api).
✔  functions[indexUsers]: firestore function initialized.
✔  functions[indexSubCategories]: firestore function initialized.
✔  functions[indexEvents]: firestore function initialized.
✔  functions[userAddedToGroup]: firestore function initialized.
i  functions[calculateLeaderBoard]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[missionsUpdate]: function ignored because the pubsub emulator does not exist or is not running.
✔  emulators: All emulators started, it is now safe to connect.

The request on the browser: enter image description here

The URL: http://localhost:8080/google.firestore.v1.Firestore/Write/channel?database=projects%2Fmyproject-dev%2Fdatabases%2F(default)&VER=8&SID=903C90XBoxaq2ebEje1QiA%3D%3D&RID=20247&AID=1&zx=11v7ij6jyefd&t=1

What am I missing??

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Adi Azarya
  • 4,015
  • 3
  • 18
  • 26
  • 1
    You focused on the `databaseURL: 'https://myproject-dev.firebaseio.com'` in your config sample. Keep in mind that this is the URL of the Realtime Database, and not of Cloud Firestore. While both databases are part of Firebase, they are completely separate, and each has/requires its own configuration data. – Frank van Puffelen May 12 '20 at 13:12
  • Could you show the values of `field`, `id`, and `params` for a request that hangs? – Sam Stern May 12 '20 at 13:19
  • Thank you for your comment. I have 2 projects prod & dev also I have the emulator dataset. I initialize the web application with the development configuration - with no special reason (according to google guide). I focused on the ```databaseURL``` because I don't know if the problem is related to this attribute. I have tried to set ```localhost:8080``` as well :| – Adi Azarya May 12 '20 at 13:27
  • @SamStern Sure. ```field``` is the collection I want to update, for example, ```user```, ```id``` is the id of this specific user, ```params``` are the values for this user.for example ```{ imageUrl: link, name: Adi }``` – Adi Azarya May 12 '20 at 13:32
  • @AdiAzarya this seems like a bug in the Firestore emulator, would you mind moving this to a GitHub issue on the firebase-tools repo? Please provide the information in your question and also the contents of `firestore-debug.log` – Sam Stern May 12 '20 at 15:36
  • @SamStern Thank you. Sure, I will move this to a GitHub on the firebase-tools repo within few hours :) – Adi Azarya May 12 '20 at 15:52
  • @SamStern https://github.com/firebase/firebase-tools/issues/2237 here it is :) – Adi Azarya May 13 '20 at 09:57

0 Answers0