我正在参考Firebase文档中的云功能来安排功能。但是尝试部署时出现以下错误。
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)
我只是尝试部署文档中的确切功能,但是它给出了错误。
我尝试部署的代码,
const functions = require('firebase-functions');
export scheduledFunction = functions.pubsub.schedule('5 23 * * *').onRun((context) => {
console.log('This will be run at 23.05 UTC');
});
我的版本:
Firebase / firebase-tools:7.0.0
节点:11.11.0
npm:6.7.0
文档 https://firebase.google.com/docs/functions/schedule-functions
答案 0 :(得分:1)
以下方法应该起作用:
const functions = require('firebase-functions');
exports.scheduledFunction = functions.pubsub.schedule('5 23 * * *').onRun((context) => {
console.log('This will be run at 23.05 UTC');
});
请参见https://firebase.google.com/docs/functions/get-started和https://cloud.google.com/functions/docs/writing/