[英]Cloud functions for firebase can not use serverTimestamp
I am currently using Cloud functions for firebase with node.js of typescript. The code is as follows我目前使用的云函数为firebase和typescript的node.js。代码如下
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
TypeError: 无法读取未定义的属性“serverTimestamp”\n
If I comment out the serverTimestamp() line it succeeds.如果我注释掉 serverTimestamp() 行,它就会成功。 I didn't care about this because it's not web, but is it related to v8 or v9?
我没有关心这个,因为它不是web,但它与v8或v9有关吗? The only two that are in the package are
package 中仅有的两个是
"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.我不确定 node_module 的版本如何改变,即使 pubspeck.lock 没有改变,或者是否使用了全局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.