1

I am migrating my Firebase Cloud Functions project from v1 to v2.

Since Auth triggers are not yet available in v2, I still have auth triggers in v1 — but all my Firestore triggers are now v2.

All of my Firestore v2 triggers fail immediately on invocation with this error: (emulator & firebase instance both)

TypeError: Cannot read properties of undefined (reading 'cloud')
    at Function.decode (/Users/.../node_modules/firebase-functions/protos/compiledFirestore.js:1529:130)
    at createBeforeSnapshotFromProtobuf (/Users/.../node_modules/firebase-functions/lib/common/providers/firestore.js:73:52)
    at createBeforeSnapshot (/Users/.../node_modules/firebase-functions/lib/v2/providers/firestore.js:187:65)
    at makeChangedFirestoreEvent (/Users/.../node_modules/firebase-functions/lib/v2/providers/firestore.js:235:37)
    at func (/Users/.../node_modules/firebase-functions/lib/v2/providers/firestore.js:316:32)
    at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:532:16
    at runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:514:15)
    at runCloudEvent (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:11)
    at processBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:498:16)

There is also this related error logged right above it:

Error: Failed to decode protobuf and create a before snapshot.\n    
at entryFromArgs (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/logger/index.js:133:19)\n    
at Object.error (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/logger/index.js:120:11)\n    
at createBeforeSnapshotFromProtobuf (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/common/providers/firestore.js:77:16)\n    
at createBeforeSnapshot (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/v2/providers/firestore.js:187:65)\n    
at makeChangedFirestoreEvent (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/v2/providers/firestore.js:235:37)\n    
at func (/Users/abhijeetkharatmol/Desktop/Workspace/market-ring/marketring-firebase/functions/node_modules/firebase-functions/lib/v2/providers/firestore.js:316:32)\n    
at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:532:16\n    
at runFunction (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:514:15)\n    
at runCloudEvent (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:531:11)\n    
at processBackground (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:498:16)

package.json

{
  "name": "functions",
  "scripts": {
    "build": "tsc",
    "build:watch": "tsc --watch",
    "serve": "npm run build && firebase emulators:start",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "22"
  },
  "main": "lib/index.js",
  "dependencies": {
    "aws-sdk": "2.1692.0",
    "axios": "1.13.2",
    "breezeconnect": "1.0.29",
    "dhanhq": "1.0.6",
    "dotenv": "17.2.3",
    "firebase-admin": "13.6.0",
    "firebase-functions": "6.6.0",
    "fyers-api-v3": "1.4.2",
    "hashmap": "2.4.0",
    "jsdom": "27.1.0",
    "kiteconnect": "5.1.0",
    "luxon": "3.7.2",
    "moment": "2.30.1",
    "node-fetch": "3.3.2",
    "razorpay": "2.9.6",
    "shortid": "2.2.17",
    "simple-oauth2": "5.1.0",
    "smartapi-javascript": "1.0.27",
    "tough-cookie": "6.0.0",
    "upstox-js-sdk": "2.20.0",
    "yt-search": "2.13.1"
  },
  "devDependencies": {
    "@types/hashmap": "2.3.4",
    "@types/node-fetch": "2.6.13",
    "@types/request": "2.48.13",
    "firebase-tools": "^14.24.1",
    "typescript": "5.9.3"
  },
  "private": true
}

This is how my trigger is written (v2): The code fails as soon as it is invoked. The first line i.e. logStartOfFunction("onPrivateUserDataUpdateTrigger") does not even get executed.

exports.onPrivateUserDataUpdateTrigger = onDocumentUpdated(
  "PrivateUserData/{docId}",
  async (event) => {
    logStartOfFunction("onPrivateUserDataUpdateTrigger");
    // other logic
    logEndOfFunction("onPrivateUserDataUpdateTrigger");
  }
);
5
  • Please edit your question to show a complete example of the code that doesn't work the way you expect, along with instructions that anyone can follow to observe the same result. Right now you're not showing a complete package.json, nor complete function code. It seems you've also omitted the fact that you're using the Firebase emulator instead of deploying to the actual cloud service - is that true? Commented Nov 9 at 14:47
  • The package.json is updated now. I am getting the error in both emulator and actual firebase instance. onPrivateUserDataUpdateTrigger gets invoked when I update a document under PrivateUserData collection. The first line. i.e. logStartOfFunction("onPrivateUserDataUpdateTrigger") does not even get executed. The code fails as soon as it is triggered. So, a particular line inside that code is not breaking. Commented Nov 10 at 6:32
  • What I have understood from the error is that the framework is unable to create a 'before' snapshot of the document which is updated. The framework populates the event.data.before with the 'before' snapshot it tries to create and fails. Commented Nov 10 at 6:32
  • If your code isn't causing the failure, and you've tested this by removing everything and using an empty function, then you should consider filing a bug report with Firebase. Stack Overflow is not likely to help if the problem isn't with your own code that you can show in the question. You should provide them with the exact steps to take to reproduce the error. Commented Nov 10 at 14:22
  • I have reported this as a bug to Firebase team. Not sure if they will accept it as a bug. Meanwhile, would it be possible to try & find out what is wrong with my package.json? Is any package causing this error? I am sure, it has to be some package. Something is interfering. Firebase team won't leave such a blunder. Commented Nov 14 at 10:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.