I had this issue when I had one file with global variable declaration:
var v
and another file with local variable use but also this same local variable declaration (by accident) AFTER it was first used in a function:
function f() {
v = 5;
let v = 5;
}
So for the function f
the variable v
is local.