The Firestore hooks no longer work in my firebase project. When I try to retrieve data from the event using DeltaDocumentSnapshot.data(), I receive the following error message in the function logs:
Error: Cannot decode type from Firestore Value: {"stringValue":"world"}
firebase-functions: 0.7.4
firebase-tools: 3.16.0
firebase-admin: 5.5.1
const functions = require('firebase-functions');
exports.findSearchOnOffer = functions.firestore.document('offers/{offerId}').onCreate(event => {
console.log(event);
var offerData = event.data.data();
return 0;
});
functions/index.jsoffers collection to trigger the cloud functionFunctions deployed successfully, no errors.
It should be possible to access object data as shown in the docs
Error: Cannot decode type from Firestore Value: {"stringValue":"world"}
at DocumentSnapshot._decodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:464:15)
at DocumentSnapshot.data (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:322:26)
at exports.findSearchOnOffer.functions.firestore.document.onCreate.event (/user_code/index.js:13:30)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:59:27) at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:53:36)
at /var/tmp/worker/worker.js:695:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Here is the console output of the event:
DocumentSnapshot { _ref: DocumentReference { _firestore: Firestore { makeAuthenticatedRequest: [Object],
authClient: [Object],
baseUrl: undefined,
getCredentials: [Function: bound getCredentials],
globalInterceptors: [],
interceptors: [Object],
packageJson: [Object],
projectId: '[...]',
projectIdRequired: true,
Promise: [Function: Promise],
grpcMetadata: [Object],
maxRetries: undefined,
userAgent: 'gcloud-node-firestore/0.8.2',
activeServiceMap_: Map {},
protos: {},
_preferTransactions: true,
_lastSuccessfulRequest: null,
api: [Object],
_referencePath: [Object] },
_referencePath:
ResourcePath {
segments: [Object],
_formattedName: undefined,
_projectId: '[...]',
_databaseId: '(default)' } },
_fieldsProto: { hello: { stringValue: 'world' } },
_readTime: undefined,
_createTime: '2017-12-19T14:01:50.144095000Z',
_updateTime: '2017-12-19T14:01:50.144095000Z' }
It looks like the problem is with this line _fieldsProto: { hello: { stringValue: 'world' } }.
i'm in similar problem too
I also have that problem.
I am having the same issue with firestore and cloud functions it was working perfectly yesterday.
Same problem, didn't change the code and it's giving me this error over and over. Wasted so much time trying to debug this.
me too, I've been trying to fix it for several hours
Hi all, could you try pinning your firebase-functions version to 0.7.3 (the previous release) and redeploy your functions to see if that resolves the issue?
To help us debug, could anyone who is experiencing this error please post the contents of your package.json?
This is supposed to be fixed with SDK version 0.7.5.
Yep, the just-released version 0.7.5 of firebase-functions should resolve this error. Please update to the latest version and redeploy your functions to get the fix.
It works, thanks.
It's happening again on v0.8.1
@andoshin11 Can you check your package.json to see what firebase-admin version you have? It should be 5.8.1
Happening with 0.8.2
Edit verifying with the latest firebase-admin version per @laurenzlong comment.
Update works with "firebase-admin": "^5.11.0" and "firebase-functions": "^0.8.2"
```package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.8.2"
},
"private": true
}
$ npm ls firebase-functions
functions@ /Users/ralphs/Workspace/divvy/functions
└── [email protected]
```
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
still notworking... here is my log, cannot use snap.data();
{"_ref":{"_firestore":{"grpcMetadata":{"_internal_repr":{"x-goog-api-client":["gl-node/6.11.5 gccl/0.13.1 grpc/1.10.1"]}},"userAgent":"gcloud-node-firestore/0.13.1","activeServiceMap_":{},"protos":{},"_preferTransactions":true,"_lastSuccessfulRequest":null,"api":{"Firestore":{"auth":{"authClientPromise":{},"authClient":null,"googleAuthClient":{"jsonContent":null,"cachedCredential":null,"_cachedProjectId":null},"config":{"scopes":["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/datastore"],"projectId":"cat-properties","libName":"gccl","libVersion":"0.13.1"},"credentials":null,"environment":{},"jwtClient":null,"projectId":"cat-properties","token":null}}},"_referencePath":{"segments":[],"_projectId":"cat-properties","_databaseId":"(default)"}},"_referencePath":{"segments":["posts","2JeMu5VFWC3QOZ3fueHU"],"_projectId":"cat-properties","_databaseId":"(default)"}},"_fieldsProto":{"message":{"valueType":"stringValue","stringValue":"textislowercase666"}},"_createTime":"2018-04-09T08:10:19.591199000Z","_updateTime":"2018-04-09T08:10:19.591199000Z"}
@sattha Are you referring to a deployed function or a local emulated function?
I was unable to reproduce this bug using:
firebase-functions v1.0.1
firebase-admin v5.12.0
I deployed this function:
exports.fsAction = functions.firestore.document('input/{id}').onCreate(snap => {
console.log(snap.data())
return snap.ref.set({bar: 'faz'});
}),
snap.data() printed out "{hello: world}" as expected.
If you are seeing errors when emulating, that is a different bug, please open a new one.
Thanks @laurenzlong ! Those versions work. Haven't been able to get any other versions to work, anyone coming here use:
firebase-functions v1.0.1
firebase-admin v5.12.0
The latest versions of both of these modules should also work:
firebase-functions v1.0.3
firebase-admin v5.12.1
Please let me know if they don't
Most helpful comment
It's happening again on
v0.8.1