Closed miag676 closed 3 years ago
Thanks for reporting this! I'm looking into it.
Turns out now it only supports ES6 modules for some reason, but I may be mistaken.
As a first thing I've noticed, please use algoliaFunctions.syncAlgoliaWithFirestore(index, change)
to sync with Firestore. Types of RealtimeDatabase and Firestore changes are different, thus syncAlgoliaWithFirebase
won't work with Firestore.
If it doesn't help, I would suggest converting your functions to the ES6 module and rewrite code like this:
import { config, firestore } from "firebase-functions";
import admin from 'firebase-admin';
admin.initializeApp(config().firebase)
import algoliasearch from "algoliasearch";
import { syncAlgoliaWithFirestore } from 'algolia-firebase-functions';
const algolia = algoliasearch(functions.config().algolia.app,
functions.config().algolia.key);
const index = algolia.initIndex(functions.config().algolia.index);
export const indexTest = firestore.document('test/{document}').onCreate((change, context) =>
syncAlgoliaWithFirestore(index, change)
)
Or use Typescript in your cloud functions.
Please let me know if it works for you
Hello, thank you very much for your help. I converted the functions to ES6 as you suggested and it works now. Previously, I also tried it with firestore in the command( algoliaFunctions.syncAlgoliaWithFirestore(index, change)
), instead of firebase (as the code I posted), but it didn't work. But changing it to ES6 solves the problem.
Thanks again!
Cool, thank you! I'll update README to make it clear that the library is usable in ES6 modules only
I'm trying to use Algolia with Firebase Functions, but I get this error TypeError: Cannot read property 'exists' of undefined at Object.syncAlgoliaWithFirebase (/workspace/node_modules/algolia-firebase-functions/dist/index.js:79:23) I followed the steps on the npm algolia-firebase-functions library (https://www.npmjs.com/package/algolia-firebase-functions).
How could I get rid of this error? Any help would be appreciated!
This is my Firebase function code: