firebase函数:shell onWrite属性未定义
我试图在本地测试我的云功能。我正在使用命令firebase函数:shell onWrite属性未定义,firebase,google-cloud-functions,Firebase,Google Cloud Functions,我试图在本地测试我的云功能。我正在使用命令firebase functions:shell,它成功地启动了仿真器。我的index.ts中有以下云函数: export const stripeCharge = functions.region('europe-west1').database .ref('/payments/{userId}/{paymentId}') .onWrite(async (change, context) => { someCode
firebase functions:shell
,它成功地启动了仿真器。我的index.ts中有以下云函数:
export const stripeCharge = functions.region('europe-west1').database
.ref('/payments/{userId}/{paymentId}')
.onWrite(async (change, context) => {
someCode;
});
我了解到您应该以以下方式()调用onWrite firestore函数:
但是,这会导致以下错误:
'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.
复制后,我发现似乎有一个开放的情况下,这个问题
Firestore的类似设置很好,但问题似乎出在RTDB上,我想我们必须等到他们解决它,抱歉:(您使用的是哪个版本的node?@andresmijares您好,谢谢您的帮助。node--version
打印8.16.0
。这是个问题吗?也许,您的函数正在抱怨上下文
,在您的情况下,它正在触发一个旧版本,请尝试更新您的依赖项,并确保您的package.json列表正确节点版本我要检查的最后一件事是,在运行firebase functions:shell
之前,你是否正在运行npm run build
??这样我们就可以放弃一个传输文件问题我也有同样的问题。我在使用RTDB时无法在本地运行函数。该死,这太烦人了。你确定是同一个问题吗?我检查了你的链接dcontext
对象中的eventType
属性在他的例子中并不是未定义的,这似乎是我的问题。很可能,在这个复杂的问题中,我也尝试过firestore,并按预期工作。我也可以复制这个属性,遗憾的是,我无法在shell中测试我的RTDB函数
'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.
{
"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
}