[英]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.