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

**Code:** `undefined` · **Category:** Google Cloud / Firebase · **Seen on:** Firebase, JavaScript

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/gcp/firestore-invalid-argument-undefined-value)
