Vabtrix
Vabtrix

Reputation: 41

Getting an error related to Cloud Function Triggers and Firestore

Getting the following error on writing a simple Example function that is triggered when a User is created.

Code:

exports.createUser = functions.firestore
  .document('users/{userId}')
  .onCreate((snap, context) => {
    const newValue = snap.data();
    const name = newValue.name;
    //....do some stuff here
  });

Error Description:

Error: Cloud function needs to be called with an event parameter.If you are writing unit tests, please use the Node module firebase-functions-fake.
    at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/cloud-functions.js:84:19)
    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:766:24
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

Versions:

"firebase": "^5.3.0"

"firebase-admin": "^5.12.1"

"firebase-functions": "^1.1.0"

Just can't find what's wrong with this code. When a user document is newly created, I keep getting this error about event. Has anyone faced it before and How do I resolve this ?

Upvotes: 0

Views: 206

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317828

Your Firebase dependencies look really old. firebase-admin is now at 6.3.0 and firebase-functions is at 2.1.0. Make sure your code is using the correct APIs for the versions of these libraries you really want to use.

Upvotes: 1

Related Questions