Arosha
Arosha

Reputation: 1401

Firebase Schedule Functions giving error when deploy

I was referring Firebase documentation for cloud function to schedule a function. But It was giving following error when try to deploy.

Error: Error occurred while parsing your function triggers.

token-refresh/functions/index.js:5
export scheduledFunction = functions.pubsub.schedule('5 23 * * *').onRun((context) => {
^^^^^^

SyntaxError: Unexpected token export
    at Module._compile (internal/modules/cjs/loader.js:743:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)
    at Module.load (internal/modules/cjs/loader.js:666:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:606:12)
    at Function.Module._load (internal/modules/cjs/loader.js:598:3)
    at Module.require (internal/modules/cjs/loader.js:705:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
    at Module._compile (internal/modules/cjs/loader.js:799:30)

I just tried to deploy exact function that is in documentation, but it is giving error.

My Code I tried to deploy,

const functions = require('firebase-functions');

export scheduledFunction = functions.pubsub.schedule('5 23 * * *').onRun((context) => {
    console.log('This will be run at 23.05 UTC');
});

My versions:

Firebase/ firebase-tools: 7.0.0

node: 11.11.0

npm: 6.7.0

Documentation https://firebase.google.com/docs/functions/schedule-functions

Upvotes: 0

Views: 203

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83093

The following should work:

const functions = require('firebase-functions');

exports.scheduledFunction = functions.pubsub.schedule('5 23 * * *').onRun((context) => {
    console.log('This will be run at 23.05 UTC');
});

See https://firebase.google.com/docs/functions/get-started and https://cloud.google.com/functions/docs/writing/

Upvotes: 1

Related Questions