TypeError: Cannot read property 'exists' of undefined at Object.syncAlgoliaWithFirebase

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 (algolia-firebase-functions - npm).

This is my Firebase function code:

const functions = require("firebase-functions");
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
const db = admin.firestore()
const algoliasearch = require("algoliasearch");
const algoliaFunctions = require('algolia-firebase-functions');


const algolia = algoliasearch(functions.config().algolia.app,
                              functions.config().algolia.key);
const index = algolia.initIndex(functions.config().algolia.index);


exports.indexBesedilo = functions.firestore.document('besedila/{document}').onCreate((change, context) =>
    algoliaFunctions.syncAlgoliaWithFirebase(index, change)
)

Does anyone know why I’m getting this error? Any help would be appreciated!