我想使用 firebase 函式做一個 cron 作業,并按照這里
的檔案在
這里我寫的代碼
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;
});
但是當我想使用它來部署它時,npm run deploy我得到了這個
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)
但是打字稿在代碼編輯器上沒有給出任何錯誤
uj5u.com熱心網友回復:
我已經更正了您用于匯入模塊的代碼。這對我有用:
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;
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/315199.html
上一篇:從JSON檔案推斷字串文字型別
