web-dev-qa-db-ja.com

Firebase CloudFunctionsのconsole.logは単にログに記録されません。

私はここで髪を引き裂いています:

私は次のようなクラウド関数を持っています:

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? 
}); 

しかし、私のログステートメントは、実行されたとしても、ログに表示されません。

すなわち。サンプルログ:

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

ここで何が欠けていますか?

6
dwjohnston

問題は、関数が適切にデプロイされていなかったことです。

発生したのは、TypeScript/firebaseの設定の問題が原因でした。新しいコードは、firebaseが探していた場所とは異なる場所にコンパイルされていました。

コードをデプロイすると、古いコンパイル済みコードがまだデプロイされていました。

ここでの話の教訓は、デプロイする前に必ずdist/build/libディレクトリを削除することです。これは、firebaseが間違った場所を探している場合にエラーが発生するためです。

5
dwjohnston