- Symptom
- FirebaseError: Function setDoc() called with invalid data. Unsupported field value: undefined (found in field middleName in document users/abc)Same error from updateDoc and addDocFails only when an optional form field is left empty
- Cause
- The SDK throws on any property set to undefined unless the Firestore instance was created with ignoreUndefinedProperties. The default is to throw.
- Fix
- Initialize Firestore with ignoreUndefinedProperties true, or strip undefined fields before writing. Use null when you want the field stored as empty.
- Apply
import { initializeFirestore } from 'firebase/firestore'; const db = initializeFirestore(app, { ignoreUndefinedProperties: true }); // firebase-admin: getFirestore().settings({ ignoreUndefinedProperties: true })- Affected
- Every Firebase JS SDK version and firebase-admin Firestore throw by default; the ignoreUndefinedProperties setting exists since @firebase/firestore 1.14.6 (mid-2020)
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders