Firebase Functions呼び出し時に Error: function terminated. が発生した場合

公開日時
yarn run firebase deploy --only functions

上記コマンドでFirebase Functionsをデプロイした後、動作確認しようとした際にFunctionが呼び出せないエラーが発生した。

Firebase Consoleでエラーログを確認しても↓しか記載されておらず詳細な原因が分からない。

Error: function terminated.
Recommended action: inspect logs for termination reason.
Additional troubleshooting documentation can be found at
https://cloud.google.com/functions/docs/troubleshooting#logging
Function cannot be initialized.

この場合、ローカルで↓を実行するとエラーの詳細が確認できる。

yarn run firebase functions:log

今回の場合、Functions内で firebase-admin ではなく firebase を読み込もうとした凡ミスが原因だった…

Detailed stack trace: Error: Cannot find module 'firebase/firestore'

参考


Related #firebase

Firestore エミュレータ使用時にデータをリセットする

エミュレータの場合のみ一括削除用のAPIが用意されている

Error: Input required and not supplied: firebaseServiceAccount

Dependabotによって作成されたPull Requestのみで発生している

Firebase公式Github ActionsでPull RequestごとにHostingのプレビュー環境を作る

手軽にプレビュー環境で動作確認できるようになったので、継続的なアップデートがやりやすくなった