Repository navigation
Description
[REQUIRED] Environment info
firebase-tools: 15.32.1 — and the same code is still present in 15.35.0 (latest at time of writing; see "Version check" below)
Platform: Windows 10 Pro 10.0.19045 (x64)
Full environment where this was observed:
| Component | Version |
|---|---|
| Node.js | v24.19.0 (project declares node: "22"; emulator logged Using node@24 from host) |
| npm | 11.17.0 |
| firebase-tools | 15.32.1 |
| firebase-admin | 12.7.0 |
| firebase-functions | 7.4.0 |
| @google-cloud/firestore | 7.11.6 |
| Firestore Emulator | cloud-firestore-emulator-v1.22.0 |
| Java | OpenJDK 25.0.2 |
[REQUIRED] Test case
A ~40-line repro that needs no emulator, no network, and no installs — it only uses the firebase-admin already in your functions/ folder:
// repro.js — run with: node repro.js (from the folder that can resolve firebase-admin)
const admin = require('firebase-admin');
// ---- the code under test, copied verbatim from
// firebase-tools/lib/emulator/functionsEmulatorRuntime.js (class Proxied)
const isConstructor = (obj) => !!obj.prototype && !!obj.prototype.constructor.name;
function getOriginal(target, key) {
const value = target[key];
if (value === undefined) return undefined;
if (isConstructor(value) || typeof value !== 'function') return value;
return value.bind(target); // <-- the line under investigation
}
console.log('BEFORE:', typeof admin.firestore.FieldValue, Object.keys(admin.firestore).length);
const delivered = getOriginal(admin, 'firestore'); // what the emulator hands to user code
console.log('AFTER :', typeof delivered.FieldValue, Object.keys(delivered).length);
try {
delivered.FieldValue.serverTimestamp();
} catch (e) {
console.log('ERROR :', e.name + ': ' + e.message);
}And a zero-dependency version, if that is easier to run (no firebase-admin needed) — it reproduces the same mechanics with a hand-built namespace of the same shape:
const sdk = { FieldValue: { serverTimestamp: () => 'TS' }, Timestamp: {}, Firestore: class {} };
const ns = Object.assign((app) => `db-${app}`, sdk); // arrow fn + own props = admin.firestore's shape
const isConstructor = (o) => !!o.prototype && !!o.prototype.constructor.name;
const getOriginal = (t, k) => {
const v = t[k];
return (isConstructor(v) || typeof v !== 'function') ? v : v.bind(t);
};
const delivered = getOriginal({ firestore: ns }, 'firestore');
console.log(typeof ns.FieldValue, '->', typeof delivered.FieldValue, '| keys', Object.keys(ns).length, '->', Object.keys(delivered).length);Both scripts, plus the fix-comparison and namespace-shape scripts, are also here so you can run them directly:
https://gist.github.com/ghalebabaas/9a9eaa0ba4a090a94f44fe4407cdcf6d
[REQUIRED] Steps to reproduce
- Have a Cloud Functions project using the namespaced Admin SDK:
admin.firestore.FieldValue.serverTimestamp()(orarrayUnion,increment,admin.database.ServerValue, etc.). This is still a documented, supported import style. - Run
firebase emulators:start(Functions + Firestore) and invoke any callable/trigger over HTTP. - The handler throws immediately on the first
FieldValueuse.
Note: it must go over HTTP. Calling handler.run(request) inside the test process does not reproduce it, because the stub described below is installed only inside the Functions runtime. This is a large part of why the problem is under-reported.
[REQUIRED] Expected behavior
admin.firestore.FieldValue is defined inside the emulator exactly as it is in production — the same object, with the same members.
[REQUIRED] Actual behavior
admin.firestore inside the emulator trigger process is a bare function with zero own properties, so:
TypeError: Cannot read properties of undefined (reading 'serverTimestamp')
at auditPayload (.../functions/lib/rename-review-callables.js:125)
at async .../firebase-functions/lib/common/providers/https.js:551
at async runFunction (.../firebase-tools/lib/emulator/functionsEmulatorRuntime.js:400)
Measured in the same process that serves the request:
BEFORE (direct access, inside the trigger process)
typeof admin.firestore.FieldValue : function
Object.keys(admin.firestore).length : 27
AFTER (what the emulator hands to a Cloud Function)
typeof delivered.FieldValue : undefined
Object.keys(delivered).length : 0
same object? : false
CONSEQUENCE
TypeError: Cannot read properties of undefined (reading 'serverTimestamp')
Root cause
lib/emulator/functionsEmulatorRuntime.js wraps firebase-admin in a proxyquire-style stub (class Proxied). Property resolution goes through:
static getOriginal(target, key) {
const value = target[key];
if (!Proxied.isExists(value)) return undefined;
else if (Proxied.isConstructor(value) || typeof value !== "function") return value;
else return value.bind(target); // <-- creates a NEW function
}
static isConstructor(obj) { return !!obj.prototype && !!obj.prototype.constructor.name; }firebase-admin exposes each service namespace as an arrow function carrying the SDK namespace as own properties (firebase-admin/lib/app/firebase-namespace.js):
get firestore() {
let fn = (app) => this.ensureApp(app).firestore();
fn = Object.assign(fn, require('@google-cloud/firestore').Firestore);
return fn;
}Two facts collide:
- An arrow function has no
prototype, soisConstructor()isfalse. Function.prototype.bind()returns a new function and copies none of the original's own properties.
So every member of the namespace — FieldValue, Timestamp, Firestore, v1, v1beta1, … — is silently dropped.
Additionally: because these namespaces are arrow functions, this is lexical and bind() cannot change it. For these values the bind() branch protects nothing and only destroys properties.
Blast radius (measured, all six namespaces)
Own-member count before → after passing through getOriginal:
admin.firestore 27 -> 0
admin.auth 1 -> 0
admin.storage 1 -> 0
admin.database 8 -> 0
admin.messaging 1 -> 0
admin.app 0 -> 0
admin.database.ServerValue and admin.auth.* are affected by the same mechanism, which matches the workaround posted in #5460 (import { ServerValue } from "firebase-admin/database").
Version check
I fetched lib/emulator/functionsEmulatorRuntime.js from 15.35.0 (published 2026-11-04) and compared it to the installed 15.32.1:
- both files are 23,258 bytes, and
Proxied.getOriginalhas the identical body in both.
So this is not fixed in the latest release.
Fix analysis
I compared candidate fixes with a script (attached). The namespace has 27 enumerable members plus 4 non-enumerable ones (length, name, v1, v1beta1):
| Candidate | enumerable members | v1 / v1beta1 |
callable | verdict |
|---|---|---|---|---|
return value.bind(target) (current) |
✗ lost | ✗ lost | ✓ | the defect |
Object.assign(value.bind(target), value) |
✓ | ✗ still lost | ✓ | not sufficient |
Object.defineProperties(value.bind(target), Object.getOwnPropertyDescriptors(value)) |
✓ | ✓ | ✓ | safe |
return value (no bind) |
✓ | ✓ | ✓ | safe for arrow namespaces; may alter this semantics for a plain-function namespace |
Worth flagging: the obvious one-liner (Object.assign) does not fix it, because v1/v1beta1 are defined with enumerable: false. If the intent of bind() is to preserve this, then the descriptor-copying variant is the one that satisfies both goals.
Relation to existing issues (not a duplicate)
-
Type Error - FiedValue undefined in emulator NOT in production #5956 "Type Error - FiedValue undefined in emulator NOT in production" — closed after the reporter found the workaround
require("firebase-admin/firestore"). The underlying emulator behaviour was never diagnosed. -
Namespaced
firebase-adminaccess not working in emulator, works in production #5460 "Namespacedfirebase-adminaccess not working in emulator, works in production" — closed with the same class of workaround. In that thread a maintainer wrote:"My guess is that the difference in execution environment between the emulated and the prod environment may be due to some of the old hacks we have in the codebase that tries to monkey-patch the firebase admin sdk."
This issue is intended as the follow-up with the specific line and mechanism for that guess, rather than a re-report of the symptom. If you would prefer it tracked on one of those threads, feel free to move/close it — but the getOriginal behaviour is currently unfixed and undiagnosed in the code.
What I have NOT verified
To be explicit about the limits of this report:
- Only Windows was tested (no macOS/Linux run).
- Only firebase-admin 12.7.0 was tested (13.x not tried).
- The effect of running the emulator on Node 22 (the version this project declares) was not measured; the run above used Node 24 from the host, and the emulator warned about the mismatch.
- I did not apply or test any fix; the table above is analysis, not a verified patch.
- The blast radius is measured for the list of namespaces above; I did not enumerate every member of every namespace.
Request
Could a maintainer confirm whether:
- the
bind()branch is load-bearing for any namespace (i.e. is there a case wherethismust be rebound for a function that also carries own properties)? and - you would prefer the descriptor-copying fix, or returning the value unchanged so that the wrapping is transparent?
Happy to open a PR against whichever approach you prefer — I have a minimal patch ready and can add a regression test that asserts namespace members survive the stub.
Activity