Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase functions:shell onWrite property undefined

I am trying to test my cloud functions locally. I am using the command firebase functions:shell which starts the emulator successfully. I have the following cloud function in my index.ts:

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

I read that you should invoke an onWrite firestore function the following way (https://firebase.google.com/docs/functions/local-shell):

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

However, this results in the following error:

'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.

The error happens in some other file and I'm not sure why. What am I missing?

Edit: My 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
}
like image 469
Jesper Avatar asked Sep 15 '26 02:09

Jesper


1 Answers

After replicating this I've found this thread it looks there is an open case for this issue.

The similar setup works fine for Firestore, but the issue seems to to be with the RTDB, I assume we have to wait until they solve it, sorry :(

like image 134
andresmijares Avatar answered Sep 17 '26 07:09

andresmijares



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!