Firebase Cloud Functions TypeError: Cannot read property 'val' of undefined

I have started using fire-base functions some time back and it was in beta release.

When I try to update the functions within the production with the different node packages of firebase functions, following error occurred.



TypeError: Cannot read property 'val' of undefined
    at exports.<>.functions.database.ref.onWrite.event (/user_code/index.js:467:38)
    at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27) 

I have used number of  fire base functions  and all of them triggering based onWrite leads to the above error.

After small search I found the following discussion ,

https://stackoverflow.com/questions/49746905/firebase-typeerror-cannot-read-property-val-of-undefined?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

I have moved  from     "firebase-functions": "^0.9.1", to  "firebase-functions": "^1.0.2", where there is a major change in method definition as indicated below.

Change this:
exports.pushNotification = functions.database.ref('/messages').onWrite( event => {

const message = event.data.val();
const user = event.data.val();
});
to this:
exports.pushNotification = functions.database.ref('/messages').onWrite(( change,context) => {

const message = change.after.val();
});

Comments

Popular posts from this blog

ENOENT: no such file or directory, rename : node_modules/async

react-quill Integrate quill-image-resize-module