Skip to content

Firestore Trigger V2 typing missing #1378

Closed
@service-paradis

Description

@service-paradis

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

  1. Use TypeScript
  2. 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:

  1. remove Change from firebase-functions/v2/firestore and import it using import { Change } from 'firebase-functions';
  2. use event.data.before and event.data.after instead of event.data.change.before or event.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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions