简体   繁体   English

firebase部署错误:“解析函数触发器时发生错误”

[英]firebase deployment error:“error occured while parsing your function triggers”

I am having an error while deploying a function as "error occured while parsing your function triggers" and syntax error at the line firestore.collection('orders').get() as syntax error: unexpected token '.' 我在部署函数时遇到错误,因为“解析函数触发器时发生错误”,并且在firestore.collection('orders').get() syntax error: unexpected token '.'syntax error: unexpected token '.' . My node version is v8.11.3. 我的节点版本是v8.11.3。 I tried the command to update my node version: npm install -g firebase-tools@latest but the error still remains the same. 我尝试了以下命令来更新节点版本: npm install -g firebase-tools@latest但错误仍然相同。 Can you help me out with this? 你能帮我这个忙吗? This is my code. 这是我的代码。

const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
var firestore = admin.firestore();

exports.webhook = functions.https.onRequest((request, response) => {

    console.log("request.body.result.parameters: ", request.body.result.parameters);
    switch(request.body.result.action)
    {
        case'bookhotel':
            let params = request.body.result.parameters;

            firestore.collection('orders').add(params)
            .then((docRef) => {

                console.log("docRef: ", docRef);
                response.send({
                    speech:
                        `${params["name"]} your hotel booking request for ${params["room-type"]} room is forwarded for ${params["persons"]} persons,
                     we will contact you on ${params["email"]} soon.`

                });
                return;
            })
            .catch((e => {
                console.log("error:", e);
                response.send({
                    speech: "something went wrong when writing on database"
                });
            }))
        break;
        case'showbooking':
            firestore.collection('orders').get()
            .then((querySnapshot))=>{
                var orders=[];
                querySnapshot.forEach((doc)=>{orders.push(doc.data()) });

                var speech=`you have ${orders["length"]} orders \n`;

                orders.forEach((eachOrder,index)=>{
                    speech=`number ${index+1} is ${eachOrder["room-type"]} room for
                         ${eachOrder["persons"]} persons, ordered by ${eachOrder["name"]},
                         contact email is ${eachOrder["email"]}`
                    })
                    response.send({
                        speech:speech
                    });
                })
                .catch((err)=>{
                    console.log('error getting documents',err);

                    response.send({
                        speech: "something went wrong when reading from database"
                    })
                })
        break;

        default:
            response.send({
                speech:"no action matched in webhook"
            })
    }
});

I copied your code into VS Code, and it gave me a different errors. 我将您的代码复制到VS Code中,这给了我一个不同的错误。

First, you need curly braces around your case blocks. 首先,您需要在案盒周围加上花括号。 Instead of this: 代替这个:

switch (thing) {
    case 'option1':
        statement;
        statement;
        break:
}

It should be like this: 应该是这样的:

switch (thing) {
    case 'option1': {
        statement;
        statement;
        break:
    }
}

Note the curly braces surrounding the block of statements. 注意语句块周围的花括号。

Also you have one too many parenthesis on this line: 同样,您在此行上有太多括号:

.then((querySnapshot))=>{

It should be: 它应该是:

.then((querySnapshot)=>{

After that, the code compiles fine. 之后,代码可以正常编译。

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

相关问题 Firebase部署错误:解析函数触发器时发生错误 - Firebase Deploy Error: Error occurred while parsing your function triggers 解析功能触发器时出现Firebase错误 - Cloud Functions for Firebase Error occurred while parsing your function triggers Firebase函数部署错误:解析函数触发器时发生错误 - Firebase Functions deploy error : Error occurred while parsing your function triggers 错误:在部署云功能时解析触发器时出错 - Firebase - Error: Error parsing triggers while deploying cloud functions - Firebase Firebase:解析触发器时出错:无法找到模块'request-promise'简单云功能 - Firebase: Error parsing triggers: Cannot find module 'request-promise' simple cloud function 部署Firebase时解析错误 - Parsing error while deploying firebase 获取 `eslint' - 解析错误,同时编译 firebase 云 function - Getting `eslint' - parsing error, while compiling firebase cloud function 错误解析错误:将功能部署到Firebase时,无效的正则表达式标志 - error Parsing error: Invalid regular expression flag while deploying function to firebase 使用Javascript解析Firebase CLI函数中的错误 - Parsing error in Firebase CLI function in Javascript Firebase function NodeJS 抛出解析错误 - Firebase function NodeJS throwing parsing error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM