【问题标题】:'Function returned undefined, expected Promise or value' with a function that just prints log“函数返回未定义的、预期的承诺或值”,函数只打印日志
【发布时间】:2018-09-03 04:15:38
【问题描述】:

已经有数百个类似的问题,其中大多数的答案都建议return 某事。我做到了。

我学会了实现云函数并编写了一个函数来处理write 事件。那没有用,所以我递归地减少了函数,以归结为一行也不起作用的代码。

我的代码如下。

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

exports.demofunc = 
  functions.database
    .ref('/exportable/[some_long_ref]/newContacts')
    .onWrite(event => {
      console.log('Ok something changed')
      return true
    })

我希望这至少可以工作,但它没有

我得到的日志如下

Function execution took 413 ms, finished with status: 'ok'
Function returned undefined, expected Promise or value
Function execution started

//[As you'd expect these logs are in reverse order.]

我也试过return 0,但没有成功。

您现在可能已经意识到,这是我第一次尝试使用云函数和 JS。

任何帮助表示赞赏。

【问题讨论】:

  • 日志输出是否包含Ok something changed?并且是日志输出左边的函数名demofunc
  • 好吧,Ok something changed 没有打印在日志中。错误旁边的函数名称是我的函数名称,我已将其更改为 dempfunc 用于堆栈溢出。
  • 我的猜测是你没有成功部署你修改后的代码。再次尝试部署并在部署日志中查找functions[yourFunctionName]: Successful update operation
  • 我确实看到每次部署时都会进行编辑,然后是 Deploy complete!。我想这不是问题。我仍然会尝试编写一个新函数 all-to-gather 看看是否是这样,但我坚信不是。
  • 我复制并运行了您发布的代码:没有错误并且日志输出包含Ok something changed。我怀疑您实际上并没有部署发布的代码。也许另一个 index.js 文件?

标签: javascript firebase promise google-cloud-functions


【解决方案1】:

所以我通过在我的系统上重新安装 firebase-functions 包解决了这个问题。我记得我在安装时遇到了一个我忽略的问题,这也是阻碍的同一件事。

我在本地控制台中收到了一条日志,上面写着Deployed successfully,但实际上并没有成功部署。

感谢 Bob(在有问题的 cmets 中)让我知道代码没有问题。

【讨论】:

    猜你喜欢
    • 2020-12-23
    • 2019-06-09
    • 2018-06-17
    • 1970-01-01
    • 2018-09-27
    • 2018-12-17
    • 2019-05-11
    • 1970-01-01
    • 2018-12-05
    相关资源
    最近更新 更多