Firebase Cloud Functions上的console.log根本不会记录。

dwj*_*ton 5 google-cloud-functions google-cloud-firestore

我在这里扯头发:

我有一个如下所示的云函数:

exports.stripeCharge = functions.firestore.document('/payments/{paymentId}')
    .onWrite((doc, context) => {
        console.log("hello?");

        const payment = doc.after.data();

        // Snip - What happens here shouldn't affect whether the log show or not right? 
}); 
Run Code Online (Sandbox Code Playgroud)

但是我的日志语句根本不会显示在我的日志中,即使执行也是如此。

即。样本日志:

5:04:40.084 PM
stripeCharge
Function execution took 288 ms, finished with status: 'ok'
5:04:40.077 PM
stripeCharge
Function returned undefined, expected Promise or value
5:04:39.797 PM
stripeCharge
Function execution started
5:04:13.583 PM
stripeCharge
Function execution took 10195 ms, finished with status: 'ok'
5:04:07.696 PM
stripeCharge
The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods: const firestore = new Firestore(); const settings = {/* your settings... */ timestampsInSnapshots: true}; firestore.settings(settings); With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example: // Old: const date = snapshot.get('created_at'); // New: const timestamp = snapshot.get('created_at'); const date = timestamp.toDate(); Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will change to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
5:04:03.390 PM
stripeCharge
Function execution started
Run Code Online (Sandbox Code Playgroud)

我在这里想念什么?

dwj*_*ton 5

好的,问题最终在于该功能未正确部署。

发生的事情归因于一些打字稿/ firebase配置问题-新代码被编译到了firebase所不需要的位置。

部署代码时-一些旧的已编译代码仍在那里要部署。

这个故事的寓意是:请确保在部署之前删除dist / build / lib目录-因为如果firebase在错误的位置查找,那将导致错误。