Description
Related issues
None
[REQUIRED] Version info
node: 18.13.0
firebase-functions: 4.3.0
firebase-tools: 11.27.0
firebase-admin: 11.6.0
[REQUIRED] Test case
Please follow the instructions provided in the official Firebase documentation at https://firebase.google.com/docs/functions/beta/firestore-events?hl=fr#trigger_a_function_for_all_changes_to_a_document.
[REQUIRED] Steps to reproduce
- Use TypeScript
- Add
import { onDocumentWritten, Change, FirestoreEvent } from 'firebase-functions/v2/firestore';
to a file
[REQUIRED] Expected behavior
The function should work as described in the documentation.
[REQUIRED] Actual behavior
After building or serving the functions, I encountered an error message that says:
Module '"firebase-functions/v2/firestore"' declares 'Change' locally, but it is not exported.
node_modules/firebase-functions/lib/v2/providers/firestore.d.ts:3:10
3 import { Change, CloudEvent, CloudFunction } from "../core";
~~~~~~
'Change' is declared here.
To resolve this error, I removed Change
from firebase-functions/v2/firestore
and instead used import { Change } from 'firebase-functions'
.
However, even after this modification, the function still did not work as stated in the documentation. I had to replace event.data.change.before
and event.data.change.after
with event.data.before
and event.data.after
, respectively, to get the desired results.
Were you able to successfully deploy your functions?
To compile the functions successfully, I had to make two changes:
- remove
Change
fromfirebase-functions/v2/firestore
and import it usingimport { Change } from 'firebase-functions';
- use
event.data.before
andevent.data.after
instead ofevent.data.change.before
orevent.data.change.after
After these changes, Typescript stopped complaining. However, even after making these changes, the emulator did not recognize the function, and as a result, it did not work.