This firebase function which triggers firebase messaging fails due to unknown error
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
const messaging = admin.messaging();
export const sendChatNotification = functions.firestore.document('chats/{chatId}/messages/{messageId}').onCreate(async (snapshot) => {
const message = {
notification: {
title: `Message from test`,
body: `You have a new message from test`
},
topic: 'ueyANM8p3kSGaeVpVBcVw6cCzYK2',
data: {
chatId: snapshot.id,
},
};
return messaging.send(message)
}
error i get –
[debug] [2023-01-15T21:09:02.049Z] Error: Failed to update function sendChatNotification in region us-central1
at /opt/homebrew/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:41:11
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Fabricator.updateV1Function (/opt/homebrew/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:305:32)
at async Fabricator.updateEndpoint (/opt/homebrew/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:140:13)
at async handle (/opt/homebrew/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:78:17)
[error]
[error] Error: There was an error deploying functions
Firebase tools version – 11.13.0, updated to 11.14.0 but still same error
2
Answers
The error is occurred due to an issue from firebase end and not because of any issues from my deployment. It worked after trying several days later.
The error that you have posted sometime may not give a direct indication of the issue with the cloud function deployment.Hence if you get error try to debug at initial stage with the following steps to better understand the cause:
1.Add the command line option –debug"
firebase deploy --debug --only functions
2.Check the logs for messages:
firebase functions:log
As per what this seems to be at first glance is an issue initializing the firebase admin thus it is getting error updating the function , so try and add the following after the import code and check if you still get the issue:
Also check out these following example with similar implementation: