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
TypeError: Cannot read property 'document' of undefined
at Object.
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.
Errors in the console logs
Screenshots
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.
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.
`
Me too:
exports.usernameChanged = functions.firestore.document('/users/{userId}').onUpdate(event => {
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'document' of undefined
at Object.
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.
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
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 (/private/var/folders/nw/yppj5c0x1_b2_x9cqld6ptrr0000gn/T/fbfn_130718HZ9Kn2sCicO/index.js:19:45) (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)
at Object.
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.
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