Home > Enterprise >  TypeError: Cannot read property 'pubsub' of undefined
TypeError: Cannot read property 'pubsub' of undefined

Time:10-15

I want to make a cron job using firebase function and followed the documentation here

here my code i wrote

import functions from "firebase-functions";

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

But when i want to deploy it using npm run deploy i got this

TypeError: Cannot read property 'pubsub' of undefined
    at Object.<anonymous> (C:\Users\Fajar Alnito\Documents\work\axie-boxy\functions\lib\index.js:106:51)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at loadModule (C:\Users\Fajar Alnito\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\runtimes\node\triggerParser.js:10:16)
    at C:\Users\Fajar Alnito\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\runtimes\node\triggerParser.js:34:21
    at Object.<anonymous> (C:\Users\Fajar Alnito\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\runtimes\node\triggerParser.js:72:3)

but typescript doesn't give any error on the code editor

CodePudding user response:

I've corrected your code for importing modules. This worked for me:

import * as functions from "firebase-functions";

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
  console.log('This will be run every 5 minutes!');
  return null;
});
  • Related