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 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??