【问题标题】:How to update documents from firebase functions? [duplicate]如何从 firebase 函数更新文档? [复制]
【发布时间】:2019-09-16 09:34:24
【问题描述】:

我正在触发文档更改的功能,我需要更新另一个功能,但我遇到了错误。

我在尝试阅读一个文档时遇到了同样的错误。

我已经删除了除 firebase-admin、firebase-functions 之外的所有软件包

我已将我的代码恢复为只有一个功能。

/user_code/node_modules/firebase-admin/node_modules/gaxios/build/src/index.js:28
async function request(opts) {
      ^^^^^^^^

SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/node_modules/firebase-admin/node_modules/gtoken/build/src/index.js:18:18)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)

我希望更新文档或检索文档,但我遇到了该错误。我该如何解决这个问题?

【问题讨论】:

  • 请向我们展示您的代码。你有一个语法错误
  • 你使用哪个节点版本?
  • 我正在使用 Node v10.15.3 `exports.helloWorld = functions.firestore.document('test/{id}').onCreate((event, context) => { return admin.firestore ().collection('test2').add(event.data()) .catch(error => { console.log(error); }) }) `

标签: firebase google-cloud-functions


【解决方案1】:

我相信您使用的是旧版本的 Node.js。低于 7.6 的 Node 版本不支持异步函数。

如果您想使用 async/await,那么您需要使用 Babel 为您的节点版本进行转译。

【讨论】:

  • 我正在使用节点 -10.15.3
猜你喜欢
  • 2019-12-04
  • 2019-02-06
  • 2019-10-06
  • 2016-07-08
  • 1970-01-01
  • 2019-05-19
  • 2021-05-20
  • 2018-09-15
  • 1970-01-01
相关资源
最近更新 更多