Firebase Cloud Functions : How to split a function into multiple files?
Patrick386 opened this issue · 1 comments
Patrick386 commented
Firebase cloud functions: TypeScrip How to split a function into multiple files?
I want to use admin and searchClient in different files.
export = {admin, searchClient}; Adding this code throws an error.
Error: Failed to load function definition from source: Failed to generate manifest from function source: RangeError: Maximum call stack size exceeded
Index.ts
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
admin.initializeApp(functions.config().firebase);
const searchClient = algoliasearch(env.algolia.appid, env.algolia.apikey);
....
exports.query = require('./query');
exports.products = require('./products');
query.ts
import * as functions from 'firebase-functions';
import {searchClient} from "./index";
const requestIndex = searchClient.initIndex("allRequests");
products.ts
import * as functions from 'firebase-functions';
import {admin} from "./index";
const firestoreDb = admin.firestore();
Patrick386 commented
The problem was fixed by splitting the initial setup routine into a new file.