Firestore: Function setDoc() called with invalid data. Unsupported field value: undefined

A write contained a field whose value is undefined, which Firestore doesn't accept.

Exact message you may see Function setDoc() called with invalid data. Unsupported field value: undefinedUnsupported field value: undefined (found in field)Cannot use "undefined" as a Firestore valueValue for argument "data" is not a valid Firestore document. Cannot use "undefined" as a Firestore valueinvalid-argument undefined Firestore
Seen on: Firebase JavaScript

Meaning

Remove undefined fields before writing, replace them with null, or enable ignoreUndefinedProperties: true in the Firestore settings (admin: settings({ignoreUndefinedProperties: true})). Also watch out for nested objects, NaN and custom class instances.

Common causes

  • Optional property left undefined
  • Form field missing
  • Nested object with undefined
  • Class instance instead of plain object
  • Spread of API data with missing keys

⚡ Quick fix

  1. Strip undefined keys or use null
  2. Enable ignoreUndefinedProperties
  3. Convert class instances to plain objects

Detailed fix by platform

JavaScript

  1. const db = initializeFirestore(app, { ignoreUndefinedProperties: true });

How to diagnose

  1. Undefined — Present?
  2. Nested — Checked?
  3. Setting — ignoreUndefined?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

ALREADY_EXISTS — Firestore: 6 ALREADY_EXISTS — document already exists (create() on an existing document) (Google Cloud / Firebase)ALREADY_EXISTSauth/weak-password — Firebase Auth: auth/weak-password — Password should be at least 6 characters (Google Cloud / Firebase)auth/weak-passwordCastError ObjectId — CastError: Cast to ObjectId failed for value "x" (type string) at path "_id" (Node.js)CastError ObjectIderror converting YAML to JSON — error converting YAML to JSON: yaml: line 12: did not find expected key (Kubernetes)error converting YAML…Firestore: DEADLINE_EXCEEDED / UNAVAILABLE — Firestore: 4 DEADLINE_EXCEEDED: Deadline exceeded / 14 UNAVAILABLE: The service is currently unavailable (Google Cloud / Firebase)Firestore: DEADLINE_E…Firestore: Document exceeds the maximum size of 1,048,576 bytes — Firestore: 3 INVALID_ARGUMENT: The value of property "data" is longer than 1048487 bytes / Document exceeds the maximum size (Google Cloud / Firebase)Firestore: Document e…hotspotting — Firestore write latency/errors: hotspotting from sequential document IDs or indexed fields (Google Cloud / Firebase)hotspottingInvalid value for input variable — Terraform: Error: Invalid value for variable — "instance_type" must be a t3 type / The given value is not suitable for var.x declared at variables.tf:1,1-17: string required (Terraform)Invalid value for inp…undefined

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.