Hey there! I'm building an application and we're working with a team to integrate their API so custom events are triggered and sent to their database. We're trying to use firebase functions but keep running into issues with error saying "X is not a function"
I'm attempting to send an event for when a user is created and when a user's signedUp property changes to TRUE
Here is my code
Hi @NewGameJay,
Welcome to Google Cloud community!
I understand that you're implementing a function that's triggered by an event when a user signs up, but to narrow things down, let's focus first on the nature of your Cloud Firestore function code.
You mentioned that you had an error similar to "X is not a function". Could this actually be something similar to TypeError: functions.firestore.document(...).onCreate is not a function
? If so, errors like that could indicate that either the function event type is unrecognizable or even if it is, the written function code doesn’t align with the latest changes applied in the latest version of ‘firebase-functions’. Otherwise, it would be best if you can provide the exact error message raised during the deployment failure.
As a first approach, ensure that you're using the latest Firebase CLI and ‘firebase-functions’ versions.
I verified in your code that you're using a document.onCreate event for a Cloud Firestore trigger, but it appears that this is for 1st gen. It's still supported to use the 1st gen, but make sure to change your import statement from
const functions = require("firebase-functions");
to
const functions = require('firebase-functions/v1');
This recommendation has also been covered in a similar GitHub post.
Firebase Cloud Run functions currently has 2nd gen support, and it's recommended for developers to migrate from v1 to v2 as much as possible. In your case, this might be the opportunity for you to migrate your functions.firestore.document(...).onCreate function to its version 2 counterpart. For more information, you can also check the complete migration guideline.
I hope the above information is helpful.