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");
}
);