繁体   English   中英

Firebase Function 部署失败

[英]Firebase Function deployment fail

由于未知错误,触发 firebase 消息的此 firebase function 失败

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

我得到的错误 -

[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 工具版本 - 11.13.0,更新到 11.14.0 但仍然有同样的错误

您有时发布的错误可能不会直接指示云 function 部署的问题。因此,如果您遇到错误,请尝试在初始阶段通过以下步骤进行调试以更好地了解原因:
1.增加命令行选项--debug”
firebase deploy --debug --only functions
2.检查消息日志:
firebase functions:log
乍一看这似乎是初始化 firebase 管理员的问题,因此它在更新 function 时出错,因此请尝试在导入代码后添加以下内容并检查是否仍然遇到问题:

admin.initializeApp(); 

另请查看以下具有类似实现的示例:

该错误是由于 firebase 结束时出现的问题而不是因为我的部署存在任何问题。 几天后尝试后它起作用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM