Reputation: 41
Trying to deploy a function with OnCreate triggered for a database but it keeps returning me this error. Here's the simple code and the error response:
Just not able to figure out why the match undefined error?
Versions of Modules:
nodejs: Version 8.11.3
Function : deployed with node 8 runtime version.
"firebase": "^5.3.0"
"firebase-admin": "^5.12.1"
"firebase-functions": "^1.1.0"
"typescript": "^2.5.3"
Code:
import functions = require('firebase-functions');
import admin = require('firebase-admin');
exports.functionName = functions.database.ref('/user/{uid}/email').onCreate((snap, context) => {
console.log(snap.val());
});
Question Update: This is the latest and most updated code. I am trying to get the details of the object newly added.
Error there is a new element added to user in firebase database:
TypeError: Cannot read property 'match' of undefined
at resourceToInstanceAndPath (/srv/node_modules/firebase-functions/lib/providers/database.js:154:26)
at dataConstructor (/srv/node_modules/firebase-functions/lib/providers/database.js:122:38)
at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/cloud-functions.js:89:32)
at Generator.next (<anonymous>)
at /srv/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at new Promise (<anonymous>)
at __awaiter (/srv/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /worker/worker.js:728:24
at <anonymous>
Upvotes: 3
Views: 2796
Reputation: 228
I had the same error, when i deployed i had this warning:
⚠ functions: You must have a firebase-functions version that is at least 2.0.0. Please run npm i --save firebase-functions@latest in the functions folder.
after i installed the last firebase-functions version it worked.
So my solution was:
npm i --save firebase-functions@latest
Upvotes: 1
Reputation: 13457
I had this problem and found that my Cloud Function trigger event type (write) and my call to firebase.database.ref('...').onChange(...)
were mismatched. Once I switched the call to firebase.database.ref('...').onWrite(...)
, everything worked great!
Kind of a stupid mistake on my part. Hope this is helpful to someone else!
Upvotes: 0
Reputation: 1
I have this problem as well, and i believe its related to using node8 in the firebase functions. at least thats the last major change.
Upvotes: 0
Reputation: 83191
You are using the "old" syntax of Cloud Functions (prior to version 1.0.0 of the Firebase SDK for Cloud Functions) with onCreate((event) => {})
and the version of the SDK in your project is version 1.1.0.
You should change the syntax to
.onCreate((snap, context) => {})
as explained in the documentation
Upvotes: 1