Javascript 将firebase云函数拆分为不同文件的正确方法是什么?

Javascript 将firebase云函数拆分为不同文件的正确方法是什么?,javascript,node.js,google-cloud-functions,Javascript,Node.js,Google Cloud Functions,我正在尝试将一个大型云函数拆分为一个更小、更易于维护的文件。但是,在部署时,我总是会遇到相同的错误: Error occurred while parsing your function triggers. /Users/Raphi/Documents/Programing/Development/merchantAPI/functions/index.js:2 import { DirectPost } from '../functions/merchantPost'; ^^^^^^ Sy

我正在尝试将一个大型云函数拆分为一个更小、更易于维护的文件。但是,在部署时,我总是会遇到相同的错误:

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
我昨晚大部分时间都在谷歌上搜索,但似乎没有任何相关文档

简化索引.js:

import { DirectPost } from '../functions/merchantPost';
exports.portal = functions.https.onRequest(async (request, response) => {
  var charge = new DirectPost()
})
简化的merchantPost.js:

export class DirectPost {
  constructor(){}
}
试试看

还考虑为“门户处理程序”回调创建一个单独的文件,这样您就可以执行

exports.portal = functions.https.onRequest(portalHandler);
它使index.js更干净


也可以考虑使用类型化的脚本(其中导入的东西和你在代码中所做的完全一样),这将有助于你从长远的角度防止一些讨厌的bug……

令人敬畏的,它增加了答案,所以我可以正确地标记。