I am currently using Cloud functions for firebase with node.js of typescript. The code is as follows
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
const endpoint = functions.region("asia-northeast1");
export const test = endpoint.https.onCall(async (req) => {
const original = req.hotelCode;
const writeResult = await admin
.firestore()
.collection("messages")
.add({
original: original,
created_at: admin.firestore.FieldValue.serverTimestamp(),
});
console.log(writeResult);
});
The error statement is as follows.
TypeError: Cannot read property 'serverTimestamp' of undefined\n
If I comment out the serverTimestamp() line it succeeds. I didn't care about this because it's not web, but is it related to v8 or v9? The only two that are in the package are
"firebase-admin":"^11.0.1",
"firebase-functions":"^3.23.0",
It was working normally before, so I really don't understand why I am having trouble. Please help me.
It's really odd, but I was able to do it using.
import {FieldValue} from "firebase-admin/firestore";
I'm not sure how the version of node_module can change even though the pubspeck.lock hasn't changed, or if global was used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.