firebase-fuctions,TypeError:无法读取未定义的属性“ onRequest”

时间:2019-05-10 06:27:30

标签: node.js firebase google-cloud-functions dialogflow firebase-cli

通过npm i -g firebase-tools更新了Firebase, 使用了我的Firebase ID, 在firebase上部署功能(使用firebase deploy时),此错误导致

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'onRequest' of undefined
    at Object.<anonymous> (C:\Users\umer\Desktop\learning chatbots\usingFulfilmentAsWebhook\functions\index.js:9:34)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at C:\Users\umer\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:15:15
    at Object.<anonymous> (C:\Users\umer\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:53:3)

这是代码

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

exports.webhook = functions.http.onRequest((request,response)=>{
    console.log("request.body.result.parameters", request.body.result.parameters);
    let params = request.body.result.parameters;
    response.send({
        speech: `${params.name} your hotel booking request for ${params.roomType} room is forwarded for ${params.persons} persons. We will contact you on ${params.email} soon`
    });
});

2 个答案:

答案 0 :(得分:2)

在下面一行的http中插入“ s”后尝试

exports.webhook =函数.https.onRequest((request,response)=> { ... }

答案 1 :(得分:0)

在第一行中添加

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

此外,请确保已安装必要的软件包。