[英]firebase Cloud Functions Error: RangeError: Maximum call stack size exceeded
I'm tring to get stock data from an api.我正在尝试从 api 获取股票数据。
and I want it be updated at every 12:00 PM.我希望它在每 12:00 PM 更新一次。
but when I tring to deploy this funtions, using但是当我试图部署这个功能时,使用
$firebase deploy --only functions
$firebase deploy --only 函数
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
错误:无法从源加载函数定义:无法从函数源生成清单:RangeError:超出最大调用堆栈大小
This is "index.ts" in funtions/src.这是函数/src 中的“index.ts”。
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?我应该怎么办?
Because this is your functions\src\index.ts
file, you should only be exporting Cloud Functions from it and nothing else.因为这是您的
functions\src\index.ts
文件,所以您应该只从中导出 Cloud Functions,而不是其他任何内容。
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 SDK 以在其他地方使用,请将其移动到名为
functions\src\firebase.ts
(或类似文件)的自己的文件中:
// 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.