The following exports code used to work when I set the project as CommonJS
let group: keyof typeof cloudFunctions;
// loop through all groups built above and export them
for (group in cloudFunctions) {
if (group != null) {
exports[group] = cloudFunctions[group];
}
}
Now, I am trying to convert this to ESM Module so I use ESM export, instead of CJS exports but it keeps throwing me error.
let group: keyof typeof cloudFunctions;
// loop through all groups built above and export them
for (group in cloudFunctions) {
if (group != null) {
export[group] = cloudFunctions[group];
}
}
The only way I can workaround it is to declare this statically and manually one by one OUTSIDE the for loop at the top-level.
Question: How can I adopt the similar structure I had in CJS in ESM so that I can programmatically export the functions stored inside a variable?