1
votes

My problem is trying to define a local function in Firebase Cloud Functions. I would like my function to be global and reusable, but it seems to not export when I deploy using Firebase-CLI.

function mapEvents(data) {
    // Very long calculation
    ...
    return events
}

exports.importEvents = functions.https.onRequest((req, res) => {
    ...
    const mappedEvents = mapEvents(data);
    ...
})

This is the logged error I'm getting in the Firebase console when I run importEvents:

TypeError: this.mapEvent is not a function at module.exports.importEvents.functions.https.onRequest (/user_code/index.js:199:29) at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:41)

1
I don't understand what the problem is here. It seems like you're able to call mapEvents from importEvents. - Doug Stevenson
My apologies, should've included the error message. Now edited the question. - nomadoda
That is really strange. Is the function mapEvents in Index.js? It should work fine. - JamWils
On top of what JamWils said, could you switch from arrow function to function? - A.Queue
Did you found the fix? - hkchakladar

1 Answers

2
votes

This might be late but helpful for someone else.

Since you are using arrow function on exports.importEvents

Update the mapEvents function to arrow function

const mapEvents = (data) => {
    // Very long calculation
    ...
    return events
}

Hope this helps

You can read more about Arrow Functions here

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions