Skip to content

fix: support firebase-admin v14 - #336

Draft
IzaakGough wants to merge 2 commits into
masterfrom
@invertase/support-firebase-admin-v14
Draft

fix: support firebase-admin v14#336
IzaakGough wants to merge 2 commits into
masterfrom
@invertase/support-firebase-admin-v14

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #327.

What was broken. firebase-admin v14 removed the legacy namespaced API from the root firebase-admin entry, so firestore(...) was undefined and makeDocumentSnapshot threw TypeError: (0, firebase_admin_1.firestore) is not a function. The same import broke objectToValueProto and the shipped .d.ts files.

What changed. Moved to the modular subpaths (firebase-admin/firestore, firebase-admin/app). deleteApp(app) replaces app.delete(), which is absent from the modular App. The DocumentReference branch of objectToValueProto also read a _referencePath internal that no longer exists, emitting projects//databases//<path>; it now reads the ids off the Firestore instance.

Verified. Build and suite green against admin 12.7.0, 13.10.0 and 14.3.0. The #327 reproduction runs against a packed tarball with the Firestore emulator, failing before and passing after.

Decisions. CI still only tests admin 12: firebase-functions@^4.9.0 peer-requires ^10 || ^11 || ^12, so a v14 job needs the functions bump in flight on inlined.bump-functions-dep. The peer range also drops admin ^8/^9, which the modular subpaths never supported. The makeDocumentSnapshot return type is left alone; annotating it breaks eight cloudevent/mocks/firestore/* files.

v14 removed the legacy namespaced API from the root firebase-admin entry
point, so `firestore(...)` was undefined and makeDocumentSnapshot threw.
Move to the modular subpaths (getFirestore, DocumentReference, GeoPoint,
Timestamp from firebase-admin/firestore; App, deleteApp, initializeApp,
AppOptions from firebase-admin/app).

The DocumentReference branch of objectToValueProto read a `_referencePath`
internal that no longer exists, emitting `projects//databases//<path>`.
It now reads projectId and databaseId off the Firestore instance and
includes the missing `documents` segment. The old spec assertion could
not catch this because DocumentReference.toString() returned
"[object Object]" on the bundled @google-cloud/firestore.

Drops admin ^8 and ^9 from peerDependencies. The modular subpaths have no
exports entry before v10, and this package has already imported
firebase-admin/firestore since v3.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the 'firebase-admin' dependency to '^14.3.0' and migrates imports and usage from the legacy monolithic package to modular subpaths ('firebase-admin/app' and 'firebase-admin/firestore'). Additionally, it updates TypeScript configurations to skip library checks. Feedback on these changes suggests adding a fallback to 'process.env.GCLOUD_PROJECT' when resolving the 'projectId' from a 'DocumentReference' to prevent malformed reference paths if internal properties are unresolved.

Comment on lines +216 to +218
const projectId: string =
get(val, 'firestore.projectId') ||
get(val, 'firestore._settings.projectId');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If both firestore.projectId and firestore._settings.projectId are unresolved (for example, if internal properties change in a future release of firebase-admin), projectId will be undefined. This would result in a malformed reference path containing 'undefined' (e.g., projects/undefined/databases/...).

Adding a fallback to process.env.GCLOUD_PROJECT provides a safe guard, as this environment variable is typically initialized during test setup.

Suggested change
const projectId: string =
get(val, 'firestore.projectId') ||
get(val, 'firestore._settings.projectId');
const projectId: string =
get(val, 'firestore.projectId') ||
get(val, 'firestore._settings.projectId') ||
process.env.GCLOUD_PROJECT ||
'';

The firebase-admin devDependency stays at ^12 because firebase-functions
^4.9.0 peer-requires ^10 || ^11 || ^12, so CI does not exercise v14 yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support firebase-admin v14

2 participants