Problem
I have a callable cloud function set up which writes to Firestore using the Admin SDK (node.js):
const admin = require('firebase-admin');
const functions = require("firebase-functions");
exports.myFunction = functions.https.onCall(async (data, context) => {
await admin.firestore().doc("/test").create({
timestamp: admin.firestore.FieldValue.serverTimestamp()
});
})
Testing this using the emulators. Also my packages are:
"firebase-admin": "^11.2.1",
"firebase-functions": "^4.0.2",
"firebase-tools": "11.16.0"
I am getting this error in my emulator logs:
TypeError: Cannot read properties of undefined (reading 'serverTimestamp')
I recently updated the admin SDK and the firebase-tools to the versions above, then the problem started occurring. I tried reinstalling firebase-tools and the admin SDK without luck.
Anyone have an idea of what I could try?
Found the API reference here. Instead of timestamp: admin.firestore.FieldValue.serverTimestamp()
it should be timestamp: Firestore.FieldValue.serverTimestamp()
Also import: const { Firestore } = require("firebase-admin/firestore");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With