【问题标题】:Cloud function deployment failure云功能部署失败
【发布时间】:2020-10-19 07:51:57
【问题描述】:

我正在尝试使用 Cloud Firestore 作为触发器来部署我的 Cloud Function。 Cloud 函数只是侦听我的 firestore 路径上的任何新文档创建,并将新数据记录到控制台。但是,功能部署失败,并且没有明确的错误消息。您能帮我确定可能是什么问题吗?

云功能码:

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

exports.createUser = functions.firestore
    .document('test_restaurant/{id}/reviews/{id}')
    .onCreate((snap, context) => {
    
        console.log(snap.data());
      
    });

错误日志:

2020-06-28 18:51:03.110 IST
Cloud Functions
UpdateFunction
asia-east2:function-test-2
abc@gmail.com
Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs
Expand all | Collapse all
{
 insertId: "5u231ccch0"  
 logName: "projects/fs-22/logs/cloudaudit.googleapis.com%2Factivity"  
 
operation: {
  id: "operations/ZmlyZXN0b3JlLTI0OTcwNS9hc2lhLWVhc3QyL2Z1bmN0aW9uLXRlc3QtMi9xOVJCbHpESzdjSQ"   
  last: true   
  producer: "cloudfunctions.googleapis.com"   
 }
 
protoPayload: {
  @type: "type.googleapis.com/google.cloud.audit.AuditLog"   
  
authenticationInfo: {
   principalEmail: "abc@gmail.com"    
  }
  methodName: "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction"   
  resourceName: "projects/fs-22/locations/asia-east2/functions/function-test-2"   
  serviceName: "cloudfunctions.googleapis.com"   
  
status: {
   code: 3    
   message: "Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs"    
  }
 }
 receiveTimestamp: "2020-06-28T13:21:03.364975479Z"  
 
resource: {
  
labels: {
   function_name: "function-test-2"    
   project_id: "fs-22"    
   region: "asia-east2"    
  }
  type: "cloud_function"   
 }
 severity: "ERROR"  
 timestamp: "2020-06-28T13:21:03.110Z"  
}

【问题讨论】:

  • 错误输出为您提供了检查日志的链接。你试过了吗?
  • 是的,日志没有给出任何具体错误。 @道格史蒂文森

标签: javascript google-cloud-firestore google-cloud-functions


【解决方案1】:

如果您使用 lint,则需要确保您的代码正在传递 eslint . 命令,否则您将在部署到 firebase 时遇到该错误

{
  "@type":"type.googleapis.com/google.cloud.audit.AuditLog",
  "status":{
    "code":3,
    "message":"Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging"
  },
  "authenticationInfo":{
    "principalEmail":"your_email"
  },
  "serviceName":"cloudfunctions.googleapis.com",
  "methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
  "resourceName":"projects/your_project/locations/us-central1/functions/your_func"
}

对于我的情况,我通过禁用索引上的更漂亮来修复它,此外,如果您有更多文件,则必须为每个文件禁用它。

/* eslint-disable prettier/prettier */

【讨论】:

    【解决方案2】:

    检查您的根文件夹中是否安装了一些依赖项。您应该将所有模块都安装在函数文件夹中。只有 firebase 依赖项应该在您的根文件夹中。尝试在根文件夹中执行 npm uninstall yourDependencie,然后在 root/functions 文件夹中执行 npm i yourDependencie。

    【讨论】:

      【解决方案3】:

      问题已解决。基本上错误是在文档路径中两次使用相同的通配符。导致问题的参考是 {id},我只是更改了其中一个参考。新路径为:.document('test_restaurant/{id}/reviews/{reviewsId}') 部署成功。

      【讨论】:

        猜你喜欢
        • 2022-09-01
        • 2019-01-30
        • 2021-12-31
        • 2020-05-21
        • 2023-04-01
        • 2020-02-02
        • 2018-12-06
        • 2021-10-05
        • 2021-09-22
        相关资源
        最近更新 更多