firebase-admin 14: admin.firestore is undefined ('Cannot read properties of undefined (reading 'Timestamp')'); ESM `import * as admin` already broke it in v12/13
Fix: stop using the namespaced API and import per service: import { initializeApp } from "firebase-admin/app", import { getFirestore, FieldValue, Timestamp } from "firebase-admin/firestore", import { getAuth } from "firebase-admin/auth". This works in every version from 10 to 14, in CommonJS and ESM.
What I measured in node:22 with import * as admin from "firebase-admin":
- firebase-admin 12.1.0, 12.7.0 and 13.10.0 compiled by tsc to CommonJS: admin.firestore, admin.firestore.Timestamp and admin.firestore.FieldValue are all defined.
- Same versions as native ESM (.mjs or "type": "module"): admin.firestore is undefined; the namespace object only lives on admin.default (admin.default.firestore.Timestamp is a function). So import * as admin plus admin.firestore.FieldValue fails as soon as a project switches to ESM.
- firebase-admin 14.5.1: even CommonJS gives typeof admin.firestore === "undefined"; the root module only exports initializeApp, getApp, getApps, deleteApp, applicationDefault, cert, refreshToken, FirebaseError, FirebaseAppError, AppErrorCode and SDK_VERSION. Every admin.firestore(), admin.auth() and admin.firestore.FieldValue call breaks when a caret range or a fresh npm i firebase-admin brings in 14.
The modular imports (firebase-admin/firestore) worked in all of the above.