Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
firebase Cloud Functions Error: RangeError: Maximum call stack size exceeded

I'm tring to get stock data from an api.

and I want it be updated at every 12:00 PM.

but when I tring to deploy this funtions, using

$firebase deploy --only functions

the error comes out.

Error: Failed to load function definition from source: Failed to generate manifest from function source: RangeError: Maximum call stack size exceeded

This is "index.ts" in funtions/src.

import * as functions from "firebase-functions";
import axios from "axios"
import { doc, getFirestore, setDoc, Timestamp } from 'firebase/firestore'
import { format } from 'date-fns'
import { initializeApp } from "firebase/app";

const firebaseConfig = {
    apiKey: "***********",
    authDomain: "****",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "",
    measurementId: ""
};

// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);

const API_KEY = "****************"

interface Wow {
    clpr: string
    srtnCd: string
}

const today = new Date();
const yesterday = today.setDate(today.getDate() - 1);
const basDt = format(yesterday, 'yyyyMMdd')

export const getStocks = functions
    .region('asia-northeast3')
    .pubsub.schedule('12 00 * * *')
    .timeZone('Asia/Seoul').onRun(async (context) => {
        await axios.get(`https://api.odcloud.kr/api/GetStockSecuritiesInfoService/v1/getStockPriceInfo?numOfRows=3000&resultType=json&basDt=${basDt}&serviceKey=${API_KEY}`)
            .then(response => {
                const wow: Wow[] = response.data.response.body.items.item
                wow.map((v, index) => {
                    setDoc(doc(db, 'KRX', v.srtnCd), { day: Timestamp.fromDate(today), price: v.clpr })
                })
                return null;
            })
    })

Another functions do work well . but if I include this one, It doesn't work.

What should I do?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because this is your functions\src\index.ts file, you should only be exporting Cloud Functions from it and nothing else.

So change:

// Initialize Firebase
export const app = initializeApp(firebaseConfig);
export const db = getFirestore(app);

to:

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

If you want to export an initialized Firebase SDK for use elsewhere, move it to its own file called functions\src\firebase.ts (or similar):

// firebase.ts
import { initializeApp } from "firebase-admin/app";
import { getFirestore } from "firebase-admin/firestore";

export const app = initializeApp(); // no arguments uses the default service account
export const db = getFirestore(app);

then use it like so:

import { app, db } from "./firebase.ts"

// NOTE: at time of writing, @google-cloud/firestore still uses the legacy namespaced syntax
db.doc("path/to/some/document") 
  .set({ /* data */ })
  .then(() => console.log('success'))
  .catch((err) => console.error('error', err));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!