我正在尝试使用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"
}
答案 0 :(得分:0)
问题已解决。基本上,错误是在文档路径中两次使用相同的通配符。引起问题的引用是{id},我只是更改了其中一个引用。新路径为:.document('test_restaurant / {id} / reviews / {reviewsId}'),部署成功。
答案 1 :(得分:0)
检查根文件夹中是否安装了某些依赖项。您应该将所有模块安装在functions文件夹中。只有Firebase依赖项应位于您的根文件夹中。尝试执行npm卸载根文件夹中的yourDependencie,然后再将npm替换为root / functions文件夹中的yourDependencie。
答案 2 :(得分:0)
如果您使用的是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 */