【问题标题】:ReferenceError: chapter is not definedReferenceError:未定义章节
【发布时间】:2020-03-31 02:22:10
【问题描述】:

一旦在我的收藏“我的英雄学院”中创建了一个文档,我就会尝试向特定设备发送通知。当我尝试部署该功能时,我收到以下错误 -

Error: Error occurred while parsing your function triggers.

ReferenceError: chapter is not defined

代码:

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

admin.initializeApp(functions.config().firebase);

var msgData;
var token = "####";

exports.offerTrigger = functions.firestore.document(
    'My Hero Academia'/{chapter}
    ).onCreate((snapshot,context) => {
        msgData = snapshot.data();
        var payload = {
            "notifications": {
                "title": "A new chapter has been released",
                "body": "Read chapter " + msgData.number + " now!",
                "sound": "default"
            }
        }

        return admin.messaging().sendToDevice(token,payload).then((response) => {
            console.log('Pushed notification');
        }).catch((error) => {
            console.log(error);
        })
    })

显然,我已经隐藏了我的令牌。正如错误所说,没有定义章节。但是 {chapter} 不是用来指代将要创建的新文档吗?

编辑:

{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":13,"message":"INTERNAL"},"authenticationInfo":{"principalEmail":"user2312@gmail.com"},"requestMetadata":{"requestAttributes":{},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/dmscraper-c91da/locations/us-central1/functions/offerTrigger"}

【问题讨论】:

    标签: firebase google-cloud-functions


    【解决方案1】:

    改变这个:

    functions.firestore.document(
        'My Hero Academia'/{chapter}
        ).onCreate((snapshot,context) => {
    

    进入这个:

    functions.firestore.document('My Hero Academia/{chapter}')
    .onCreate((snapshot,context) => {
    

    你应该有' 也超过{chapter}

    https://firebase.google.com/docs/firestore/extend-with-functions#wildcards-parameters

    【讨论】:

    • 试过这个,现在我得到“功能部署有以下功能错误:offerTrigger”
    • 你能检查一下firebase控制台中的functions部分吗,那里会有更多详细信息的日志
    • 哦,那行得通。非常感谢帮助的人。我已经坚持了2天。 :)
    • 没问题!祝项目顺利!
    猜你喜欢
    • 2016-01-30
    • 1970-01-01
    • 2012-08-24
    • 2015-12-07
    • 1970-01-01
    • 2015-10-04
    • 2017-04-10
    相关资源
    最近更新 更多