firebase-functions: Cannot decode type from Firestore Value

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

Version info

firebase-functions: 0.7.4

firebase-tools: 3.16.0

firebase-admin: 5.5.1

Test case

const functions = require('firebase-functions');

exports.findSearchOnOffer = functions.firestore.document('offers/{offerId}').onCreate(event => {
  console.log(event);
  var offerData = event.data.data();
  return 0;
});

Steps to reproduce

  • copy and paste the above snippet into the functions/index.js
  • deploy to Firebase
  • create a new document in the offers collection to trigger the cloud function

Were you able to successfully deploy your functions?

Functions deployed successfully, no errors.

Expected behavior

It should be possible to access object data as shown in the docs

Actual behavior

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

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