-
-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for...of loop produces "Uncaught TypeError: myObject[Symbol.iterator] is not a function" error #84
Comments
Have you imported the polyfill? |
I'm using the es6-shim node module. However, I'm not using the Babel-specific module - I'll give that a try. |
I haven't tried babel with other shims, but to use |
Just installed it. I ensured babel was explicitly installed in my node_modules ( I'm going to try explicitly including it via a |
Tried including it in the I also tried excluding my other polyfill library, but this also didn't work. Also, Symbol and Symbol.iterator are definitely polyfilled - I can run them outside the context of a for...of loop with no problems. Any other thoughts? |
|
I'd already removed es6-shim and included babel/polyfill - it's still throwing the same error. |
@andfaulkner stop... I didn't saw your code. Plain objects are not iterable. You can use something like for (let [key, value] of Object.entries(myObject)){
console.log(key, value);
} or add custom iterator to your object. |
Aha! Success! Thanks a trillion, I mean it :) |
What? Plain objects are not iterable? Why? |
Error: Uncaught TypeError: myObject[Symbol.iterator] is not a function Found a fix for the issue here: babel/babel-loader#84 Fixes #84 Signed-off-by: budparr <[email protected]>
@Polyergic https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of Only arrays etc. can be used with To iterate over the keys in an object, you need to use To iterate over the values, you can do (I just learnt this) |
@nabilfreeman When I use for ... in - I get TS1005: 'of' expected.
any idea? |
@therealwolf42 |
The first bit there seems a bit misleading Any iterable object can be used with Generally the way to iterate an object's keys these days would be
or if you polyfill
|
The real problem here is that when you try to iterate over a non-iterable object, you get a bad error message. Different implementations give different error messages, but every one I've seen has been bad.
This is not a bug in any implementation; if it's a bug in anything, it's in the language spec. The workaround I've taken to using is
|
I was having the same problem iterating over FileReader items, finally solved it using Array.from
|
The transpiler currently seems to be unable to handle for...of loops. Using them causes Uncaught TypeError: myObject[Symbol.iterator] is not a function
For example, the following code:
...which gets converted into:
...produces the following error when run:
This occurs in both Chrome and Firefox. I've tried it in several different places in my codebase, with the same result every time.
The text was updated successfully, but these errors were encountered: