Functions-samples: Cannot read property 'document' of undefined

Created on 11 Oct 2017  路  2Comments  路  Source: firebase/functions-samples

How to reproduce these conditions

Create firebase function with functions.firestore.document('/messages/{documentId}')
Sample name or URL where you found the bug

Failing Function code used (including require/import commands at the top)

Steps to set up and reproduce

Sample data pasted or attached as JSON (not an image)

Security rules used

Debug output

TypeError: Cannot read property 'document' of undefined
at Object. (/private/var/folders/h0/n48xhpys7gx3krtnwd3t518w02mj3p/T/fbfn_48543prnLWsx07lN4/index.js:50:44)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at /Users/ajasingh/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object. (/Users/ajasingh/.nvm/versions/node/v8.5.0/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)
Errors in the console logs

Screenshots

Expected behavior

Actual behavior

Most helpful comment

EDIT SOLVED

Me too:

How to reproduce these conditions

exports.usernameChanged = functions.firestore.document('/users/{userId}').onUpdate(event => {

Debug output

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'document' of undefined
at Object. (/private/var/folders/nw/yppj5c0x1_b2_x9cqld6ptrr0000gn/T/fbfn_130718HZ9Kn2sCicO/index.js:19:45)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)

SOLVED

Seems to be problem of the firebase-functions version,
for me worked:

Step1 - Update package.json versions from:
"firebase-admin": "5.1.0",
"firebase-functions": "^0.5.7"
to:
"firebase-admin": "^5.4.2",
"firebase-functions": "^0.7.1",

Step2 - Remove node_modules folder

Step3 - Run npm install

All 2 comments

I am getting the same error attempting to deploy from functions-samples/quickstarts/uppercase-firestore/

`Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'document' of undefined
at Object. (/tmp/fbfn_191254d88PpDskiHz/index.js:50:44)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /usr/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object. (/usr/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)
`

EDIT SOLVED

Me too:

How to reproduce these conditions

exports.usernameChanged = functions.firestore.document('/users/{userId}').onUpdate(event => {

Debug output

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'document' of undefined
at Object. (/private/var/folders/nw/yppj5c0x1_b2_x9cqld6ptrr0000gn/T/fbfn_130718HZ9Kn2sCicO/index.js:19:45)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)

SOLVED

Seems to be problem of the firebase-functions version,
for me worked:

Step1 - Update package.json versions from:
"firebase-admin": "5.1.0",
"firebase-functions": "^0.5.7"
to:
"firebase-admin": "^5.4.2",
"firebase-functions": "^0.7.1",

Step2 - Remove node_modules folder

Step3 - Run npm install

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IchordeDionysos picture IchordeDionysos  路  3Comments

kaceo picture kaceo  路  3Comments

aaronte picture aaronte  路  6Comments

tsaarikivi picture tsaarikivi  路  4Comments

Qzingo picture Qzingo  路  3Comments