0

All my functions used to be in a single index.js file, and everything worked properly. Now, I have divided up my functions into different files for the different functions, but one function is not working.

My index file begins like this:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

The file for the function that is not working begins like this:

const functions = require('firebase-functions');
const index = require('./index')

exports.deleteOtherData = functions.firestore
    .document('attempts/{attemptId}')
    .onDelete((snapshot, context) => {

    const rawVideoBucket = index.admin.storage().bucket('my-bucket-name');

I am now getting this error:

"TypeError: Cannot read property 'storage' of undefined"

Why? Can't I reference the admin property from the index file?

  • 1
    I'm not good at all in NodeJS, but are you sure that you haven't to export the admin variable to be able to use it in subsequent file? – guillaume blaquiere Aug 14 '22 at 18:42
  • This might help: https://stackoverflow.com/questions/43486278/how-do-i-structure-cloud-functions-for-firebase-to-deploy-multiple-functions-fro – trndjc Aug 15 '22 at 00:48
  • @guillaumeblaquiere Yes, you are right. In this particular case, I found it simplest to make the admin variable a global variable accessible in all files, since I use it in all files. – TrotterDown Aug 18 '22 at 19:05

0 Answers0