Description
When using a for loop in the top level scope (i.e. not in a function) of an app.js or alloy.js file if the variable declaration used is a block scoped variable (const/let) the below error will be thrown. This is because we try to use add the level to the global scope, but as it is block scope we can't reference it outside of the for loop.
*workaround*: Use
var
to declare the variable, or move the code into a function and call that.
*Note*: I believe by default this will only be seen on Android as babel will convert const/let to var on iOS
ERROR] TiExceptionHandler: (main) [218,218] /app.js:29
[ERROR] TiExceptionHandler: }global.col = col;
[ERROR] TiExceptionHandler: ^
[ERROR] TiExceptionHandler: ReferenceError: col is not defined
Steps to reproduce
1. Add the below code to your app.js
for (const number of [ 1, 2,3 ]) {
console.log(number);
}
2. Build to android
Actual
App will crash with above error
Expected
App should not crash
No comments