【问题标题】:firebase functions:shell onWrite property undefinedfirebase 函数:shell onWrite 属性未定义
【发布时间】:2019-06-14 07:54:00
【问题描述】:

我正在尝试在本地测试我的云功能。我正在使用命令firebase functions:shell 成功启动模拟器。我的index.ts 中有以下云功能:

export const stripeCharge = functions.region('europe-west1').database
    .ref('/payments/{userId}/{paymentId}')
    .onWrite(async (change, context) => {
        someCode;
});

我读到您应该通过以下方式调用 onWrite firestore 函数 (https://firebase.google.com/docs/functions/local-shell):

stripeCharge({before: "oldData", after: "newData"})

但是,这会导致以下错误:

'Successfully invoked function.'
firebase > !  TypeError: Cannot read property 'eventType' of undefined
    at cloudFunction (C:\Users\Jesper\intergun\functions\node_modules\firebase-functions\lib\cloud-functions.js:80:40)
    at Run (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:458:20)
    at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:442:19
    at Generator.next (<anonymous>)
    at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
    at Run (C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:435:12)
    at C:\Users\Jesper\AppData\Roaming\nvm\v8.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:457:15
    at Generator.next (<anonymous>)
!  Your function was killed because it raised an unhandled error.

错误发生在其他文件中,我不知道为什么。我错过了什么?

编辑:我的package.json

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@google-cloud/storage": "^2.5.0",
    "@types/fs-extra": "^7.0.0",
    "firebase-admin": "^8.1.0",
    "firebase-functions": "^3.0.1",
    "fs-extra": "^8.0.1",
    "mailgun-js": "^0.22.0",
    "sharp": "^0.22.1",
    "stripe": "^7.1.0"
  },
  "devDependencies": {
    "@types/sharp": "^0.22.2",
    "@types/stripe": "^6.30.0",
    "firebase-functions-test": "^0.1.6",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

【问题讨论】:

  • 你使用的是哪个版本的节点?
  • @andresmijares 嗨,感谢您的帮助。 node --version 打印 8.16.0。有问题吗?
  • 也许,您的函数在抱怨context,在您的情况下,它触发了旧版本,尝试更新您的依赖项并确保您的 package.json,列出正确的节点版本
  • 我要检查的最后一件事是,你在运行firebase functions:shell 之前运行npm run build 吗?所以我们可以丢弃一个transpile问题
  • 我也有同样的问题。使用 RTDB 时,我无法在本地运行函数。

标签: firebase google-cloud-functions


【解决方案1】:

复制此内容后,我发现 this thread 似乎有一个针对此问题的未决案例。

类似的设置适用于 Firestore,但问题似乎出在 RTDB 上,我认为我们必须等到他们解决它,抱歉 :(

【讨论】:

  • 该死,这很烦人。你确定这是同一个问题吗?我检查了你的链接,context 对象中的eventType 属性在他的情况下不是未定义的,这对我来说似乎是个问题。
  • 它很可能会复制该问题,并且还尝试使用 Firestore 并按预期工作
  • 我也可以复制这个,遗憾的是无法在 shell 中测试我的 RTDB 函数
猜你喜欢
  • 2018-03-28
  • 1970-01-01
  • 2017-08-02
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 2018-04-01
  • 2020-03-26
  • 2018-09-13
相关资源
最近更新 更多