nodejs-firestore icon indicating copy to clipboard operation
nodejs-firestore copied to clipboard

isMomentJsType - Cannot read property 'name' of undefined

Open zomble opened this issue 6 years ago • 3 comments

Environment details

  • OS: Linux
  • Node.js version: 12.14.1
  • npm version: 6.13.4
  • @google-cloud/firestore version: 3.4.0

Steps to reproduce

  1. Update from @google-cloud/firestore version 3.3.4
  2. Save an array of objects? In my case I have an array of input objects coming from graphql
  3. TypeError: Cannot read property 'name' of undefined" at isMomentJsType /node_modules/@google-cloud/firestore/build/src/serializer.js:312:27

See https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/serializer.ts#L403 isMomentJsType appears to assume a constructor will always exist and have .name

A example dump of the value being checked inside isMomentJsType

[
  [Object: null prototype] {
    test: '123',
    quantity: 1,
    name: 'Hat'
  }
]

with value.constructor being undefined

Cheers!

zomble avatar Jan 22 '20 02:01 zomble

@schmidt-sebastian Hey bud, just tagging you in because this relates to #879

zomble avatar Jan 22 '20 02:01 zomble

It's interesting that you are hitting this code path. I will fix this specific error with https://github.com/googleapis/nodejs-firestore/pull/893, but I would assume that with #893 merged you will now get an error about using an unsupported object type in your documents (https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/serializer.ts#L391). .

schmidt-sebastian avatar Jan 22 '20 06:01 schmidt-sebastian

Yes, I found it strange as well. I am digging around in graphql lib to understand why I even get the object I am getting, as it really should be a plain object.

zomble avatar Jan 22 '20 09:01 zomble