简体   繁体   English

firebase的云函数不能使用serverTimestamp

[英]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.

相关问题 您可以在 Firebase 函数中使用 firebase-admin.firebase.Timestamp 而不是 FieldValue.serverTimestamp() 吗? - Can you use firebase-admin.firebase.Timestamp instead of FieldValue.serverTimestamp() in Firebase functions? Cloud Functions - Cloud Firestore 错误:无法获取 serverTimestamp - Cloud Functions - Cloud Firestore error: can't get serverTimestamp 如何将 Firebase 参数化配置与 Typescript 一起用于 Cloud Functions? - How can I use Firebase Parameterized configuration with Typescript for Cloud Functions? 是否可以在 firebase 云函数中使用 setTimeout()? - is it possible to use setTimeout() in firebase cloud functions? Firebase RemoteConfig 是否可以从云功能访问 - Can Firebase RemoteConfig be accessed from cloud functions 有没有办法在没有 Firebase-Admin 的情况下在 Firebase Firestore JS 中使用 FieldValue.serverTimestamp() - Is there any way to use FieldValue.serverTimestamp() in Firebase Firestore JS without Firebase-Admin firebase 第 2 代的云函数 - Cloud functions for firebase generation 2 Cloud Functions for Firebase 超时 - Cloud Functions for Firebase timeout 如何在 firebase 云函数上正确使用 express-session - How to properly use express-session on firebase cloud functions 如何使用 firebase 云函数对 Firestore 数据进行逻辑处理 - How to use firebase cloud functions for logic on firestore data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM