Skip to content

Cloud Firestore node.js invalid use of type “object” as a Firestore argument #618

@kiwicopple

Description

@kiwicopple

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MacOS
  • Firebase SDK version: 8.3.0
  • Library version: _____
  • Firebase Product: Firestore database
  • Node Version: 10.15.1

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

This issue (by someone else) describes both the problem and the resolution: https://stackoverflow.com/questions/55065567/cloud-firestore-node-js-invalid-use-of-type-object-as-a-firestore-argument

For prosperity, I am facing the same problem using Node-Red to send a JSON object like this:

    payload: {
        text: "hello world",
        createdAt: new Date(),
        user: { _id: 1000 } // This causes the issue
    }

Which is then called in the function:

this.firestore.collection(col).add(payload)

And throws the error:

Invalid use of type "object" as a Firestore argument

The workaround, as the SO thread explains is to edit
node_modules/@google-cloud/firestore/build/src/serializer.js

and change isPlainObject to

function isPlainObject(input) {
    return util_1.isObject(input);
}

Is there a more permanent solution that I can use? This is fine on my development environment, but I will need to deploy this to an environment where I cannot edit node_modules

Many thanks

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions