In a NextJS app hosted on Firebase I have the following code in the file functions/src/index.ts
(i.e. Cloud functions)
for (const [level, lvlCount] of activeLevels.entries()) {
jsonResult = Object.assign({}, jsonResult, {
["Level_"+level.toString()]: lvlCount,
});
.....
}
Compiled with :
% firebase deploy --only functions
All works fine (no compile error) and when run all (Cloud functions tests) is as expected. But when I run :
% firebase deploy --only hosting
I get the error message below:
./functions/src/index.ts:205:37
Type error: Type 'IterableIterator<[any, any]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
204 |
> 205 | for (const [level, lvlCount] of activeLevels.entries()) {
| ^
206 | jsonResult = Object.assign({}, jsonResult, {
207 | ["Level_"+level.toString()]: lvlCount,
208 | });
Error: An unexpected error has occurred.
After searching I went to see the tsconfig.json file and (following some suggestions) changed:
"target": "es2017"
to:
"target": "es2015"
and then to:
"downlevelIteration": true
But in either case it did not work for me and I keep getting the error.
How can I solve this problem ?
Besides the error, I do not see why “deploy –only hosting” finds something to complain about when “deploy –only functions” has found all good. I suppose I don’t quite understand what is happening in the two processes.