【问题标题】:Deploying Function Error on Cloud Function with error code 13 and Message "INTERNAL"在云函数上部署函数错误,错误代码 13 和消息“内部”
【发布时间】:2019-12-31 08:38:09
【问题描述】:

我正在为我的应用部署 Firestore 触发器 onCreate,但每次我想部署时,它总是出错

控制台始终显示代码 13 和消息“内部”

这是控制台上出现的内容

{"@type":"type.googleapis.com/google.cloud.audit.AuditLog",
"status":{"code":13,"message":"INTERNAL"},
"authenticationInfo":{"principalEmail":"[My_EMAIL]"},
"requestMetadata":{"requestAttributes":{},"destinationAttributes":{}},
"serviceName":"cloudfunctions.googleapis.com",
"methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
"resourceName":"projects/etalase/locations/us-central1/functions/onNewMessage"}

这是我在 index.js 上的代码

exports.onNewMessage = functions.firestore
  .document('/messages/{groupChatId}/{groupChatId}/{messageFeedItem}')
  .onCreate(async (snapshot, context) => {
    const doc = snapshot.data();

    console.log('------Message Created-----');
    console.log(doc);

    const idForm = doc.userID;
    const idTo = doc.sellerID;

    console.log('Message from : ', idForm);
    console.log('Message to : ', idTo);

  });

我希望这会部署,并且每次在 {messageFeedItem} 上创建新消息时,它都会触发控制台,但即使我也无法部署它

谢谢

【问题讨论】:

标签: firebase google-cloud-functions


【解决方案1】:

你必须导入 firebase 函数

import functions = require('firebase-functions');

const functions = require('firebase-functions');

如果你这样做了,那么检查你的 package.json

【讨论】:

    【解决方案2】:

    所以现在我可以通过更改目录来部署功能

    'messages/{groupChatId}/{groupChatId}/{messageFeedItem}'

    进入

    'messages/{groupChatId}/{groupChatId2}/{messageFeedItem}'

    我的猜测是你不能与通配符同名

    【讨论】:

    • 这个!我没有意识到我在一个目录中有两次 {docId}。修复了问题!
    【解决方案3】:

    设置 Node.js 和 Firebase CLI

    在许多情况下,新功能和错误修复仅适用于 最新版本的 Firebase CLI 和 firebase-functions SDK。 经常更新 Firebase CLI 和 带有这些命令的 SDK 在您的函数文件夹中 Firebase 项目:

    npm install firebase-functions@latest firebase-admin@latest --save
    npm install -g firebase-tools
    

    【讨论】:

      【解决方案4】:

      对于那些走到这一步但仍然没有解决方案的人 - 这是我的问题所在

      exports.fnName = functions.firestore
        .document('Collection/{collId}/SubCollection/{subCollId')
        .onUpdate((change, context) => {
          ...
      });
      

      请注意文档参考末尾缺少的 '}。

      这导致部署失败并在客户端出现以下情况

      未能配置触发器提供程序

      并在函数日志中包含以下内容

      "status":{
        "code":13,
        "message":"INTERNAL"
      },
      

      【讨论】:

      • 我通过添加美元符号犯了类似的错误,例如.document('Collection/${collId}/SubCollection/{subCollId}') - 你的提示让我意识到我的错误。
      【解决方案5】:

      我的问题是因为我在通配符中使用了- 字符

      'chat/{abc-efg}'
      

      我将 - 更改为 _ 并且它可以工作

      【讨论】:

        猜你喜欢
        • 2021-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-06
        • 1970-01-01
        • 2019-09-03
        • 2021-04-10
        相关资源
        最近更新 更多