【问题标题】:Firebase Schedule Functions giving error when deployFirebase调度功能在部署时出错
【发布时间】:2019-06-19 06:52:31
【问题描述】:

我指的是 Cloud 功能的 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

【问题讨论】:

  • 错误是什么?
  • 更新了错误的问题。谢谢

标签: node.js firebase google-cloud-functions


【解决方案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-startedhttps://cloud.google.com/functions/docs/writing/

【讨论】:

  • 太棒了!它正在以这种方式工作。不知道为什么他们在 Schedule Doc 中使用了不正确的语法。无论如何感谢@Renaud。
猜你喜欢
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-19
  • 2019-03-06
  • 2021-09-25
  • 1970-01-01
相关资源
最近更新 更多