firebase-functons Node.js - TypeError: Cannot read property ... of undefined

1,677 views
Skip to first unread message

Justin Jerzak

unread,
Feb 2, 2018, 7:21:25 PM2/2/18
to Firebase Google Group
I'm seing a simple webhook throwing the following error:

node.js v8.9.4

TypeError: Cannot read property 'quantity' of undefined 
at exports.webhook.functions.https.onRequest (/user_code/index.js:14:22) 
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:41) 
at /var/tmp/worker/worker.js:671:7 
at /var/tmp/worker/worker.js:655:9 
at _combinedTickCallback (internal/process/next_tick.js:73:7) 
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

request.body.result.parameters: { Quantity: 8, FoodType: [ 'Solid Food' ], FoodSource: [ 'Refrigerator' ], Units: 'Ounces' }

package.json
...
  "dependencies": {
    "firebase-admin": "~5.8.1",
    "firebase-functions": "^0.8.1"
  },



index.js:
const functions = require('firebase-functions');

// // Create and Deploy Your First Cloud Functions
//


exports.webhook = functions.https.onRequest((request, response) => {
console.log("request.body.result.parameters: ", request.body.result.parameters);

let params = request.body.result.paramters;
response.send({
speech:
`${params.Quantity} ${params.Units} of ${params.FoodType} from the ${params.FoodSource}`

});

});

I've seen similar reports, most of which referenced an issue with version 8, which should be resolved in version 8.1 of node

Tried: 
Updated the dependency versions to older versions known to not have this issue
re-installed: npm install -g firebase-tools
Removed the 'Quantity' parameter then got the same error related to 'Units' parameter

Doug Stevenson

unread,
Feb 3, 2018, 4:10:19 PM2/3/18
to Firebase Google Group
The errors are clear that, in your function, params is undefined.  This means that request.body.result.paramters is undefined.  What exactly are you sending to your function?  Have you tried logging the value of request.body to see what it's receiving?

Doug

Renaud Tarnec

unread,
Feb 4, 2018, 11:28:29 AM2/4/18
to Firebase Google Group
It seems there is a typo in your code

params = request.body.result.paramters

and not 

params = request.body.result.paramEters

See the e missing in the first version.
Reply all
Reply to author
Forward
0 new messages