[英]Is this the correct way of returning a ES6 promise in firebase cloud functions?
[英]What is the correct way to split firebase cloud functions into different files?
我正在嘗試將大型雲功能拆分為更小的更易於維護的文件。 但是在部署時我總是得到同樣的錯誤:
Error occurred while parsing your function triggers.
/Users/Raphi/Documents/Programing/Development/merchantAPI/functions/index.js:2
import { DirectPost } from '../functions/merchantPost';
^^^^^^
SyntaxError: Cannot use import statement outside a module
我昨晚大部分時間都在谷歌上搜索,但似乎沒有任何相關文檔
簡化的 index.js:
import { DirectPost } from '../functions/merchantPost';
exports.portal = functions.https.onRequest(async (request, response) => {
var charge = new DirectPost()
})
簡化的merchantPost.js:
export class DirectPost {
constructor(){}
}
嘗試在 Node.js 中包含另一個文件中的 JavaScript 類定義。
還可以考慮為“門戶處理程序”回調制作一個單獨的文件,以便您可以
exports.portal = functions.https.onRequest(portalHandler);
它使您的 index.js 更干凈。
還可以考慮使用 TypeScript(在其中導入內容完全按照您在代碼中嘗試的方式完成),從長遠來看,這將通過防止一些令人討厭的錯誤來幫助您...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.