4

Today, there is new feature of Cloud Functions for Firebase which is running functions on a schedule. So I tried to test the sample code.

index.js file

exports.scheduledFunction = functions.pubsub.schedule(‘every 5 minutes’).onRun((context) => {
  console.log(‘This will be run every 5 minutes!’);
});

But when I tried to deploy this, I got the following error message:


Error: Error occurred while parsing your function triggers.

TypeError: functions.pubsub.schedule is not a function

My firebase tools version is 6.7 (updated today)

What is the solution?

I checked the example git code in here (https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js)

But it also cause the same error:

functions.pubsub.schedule is not a function

Can anyone help me with this problem?

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
   console.log('This will be run every 5 minutes!');
});
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Sss Steve
  • 55
  • 1
  • 1
  • 6

3 Answers3

17

The announcement blog post points out that the version of the firebase-functions module also needs to be minimum 2.3.0. Run npm install firebase-functions@latest in your functions folder to update it, then build and deploy again.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
3

Here's the documentation https://firebase.google.com/docs/functions/schedule-functions

export const scheduledFunction = functions.pubsub.schedule('every 5 minutes')
.timeZone('Asia/Jakarta')
.onRun((context) => {
    console.log('This will be run every 5 minutes!');
});

And you can set the timeZone as additional

NormsDev
  • 57
  • 1
-1

I had the same issue.

I had to update my firebase-tools to version ^6.7.2. I have also updated firebase-functions but that alone did not do the job. So I would update all firebase dependencies (firebase-tools/admin/functions).

Jürgen Brandstetter
  • 7,066
  • 3
  • 35
  • 30