Skip to content
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

React-Native: Error: undefined is not a function (evaluating \'text[typeof Symbol === \'function\' ? Symbol.iterator : \'@@iterator\']()\') #198

Closed
edolix opened this issue Mar 28, 2018 · 14 comments

Comments

@edolix
Copy link

edolix commented Mar 28, 2018

Hi, i'm using this lib in a ReactNative App and methods parse and format catch this error:

Error: undefined is not a function (evaluating \'text[typeof Symbol === \'function\' ? Symbol.iterator : \'@@iterator\']()\') drop_and_substitute_characters
....

How i'm using lib:

import { parse, format } from 'libphonenumber-js'

let p = parse('8 (800) 555 35 35', 'RU')
console.log(p)

Installed from: npm install libphonenumber-js

I'm doing something wrong?
Thanks!

@catamphetamine
Copy link
Owner

Seems that Symbol.iterator is undefined - that's what the error says.
It's not supposed to be undefined.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator
You can check that by manually editing the js file in node_modules by adding a console.log.
Perhaps your ES6 Symbol polyfill is not complete: Symbol seems to be defined but seems that it's not the ES6 Symbol.

@catamphetamine
Copy link
Owner

You can try using import 'babel-polyfill' or something like that (as the first line of your program).

@catamphetamine catamphetamine changed the title React-Native: Error on drop_and_substitute_characters React-Native: Error: undefined is not a function (evaluating \'text[typeof Symbol === \'function\' ? Symbol.iterator : \'@@iterator\']()\') Mar 28, 2018
@catamphetamine
Copy link
Owner

Or, actually, my previous comment was incorrect: the Symbol polyfill seems fine but text[Symbol.iterator] is undefined for some reason.

@edolix
Copy link
Author

edolix commented Mar 28, 2018

@catamphetamine thanks for the quick reply!

Symbol.iterator is equal to '@@iterator', text is a string (the input number) so: '8 (800) 555 35 35'.

@edolix
Copy link
Author

edolix commented Mar 28, 2018

Is the package updated on npm?

@catamphetamine
Copy link
Owner

Yeah, seems that you're not in a full ES6 environment.
Are you using Babel?

@catamphetamine
Copy link
Owner

Is the package updated on npm?

What do you mean?

@edolix
Copy link
Author

edolix commented Mar 28, 2018

Yeah, seems that you're not in a full ES6 environment.
Are you using Babel?

I'm on ReactNative but it seems that Symbol are not fully supported by RN.

facebook/react-native#15902

@catamphetamine
Copy link
Owner

Well, I could look into a way of polyfilling symbol iterator somehow.
I'll post if I find something.

@edolix
Copy link
Author

edolix commented Mar 28, 2018

I found a workaround here facebook/react-native#15902 (comment).
It seems to work!

@catamphetamine
Copy link
Owner

@edolix Yeah, that's one way to do it, and actually it's better in a sense that other libraries relying on Symbol don't break.

The other thing is that I found a way to bypass Symbol.iterator in the code and released a new version [email protected]. If you feel like trying it out (while temporarily reverting your core-js fix) then you could do that. Otherwise your present workaround seems fine.

@catamphetamine
Copy link
Owner

CC @sachinB94 @m-hosoi ^^^^^^^

@edolix
Copy link
Author

edolix commented Mar 28, 2018

If you feel like trying it out ....

SUPER! I'll try it tomorrow for sure 👍

@catamphetamine thanks again for your help!

@edolix
Copy link
Author

edolix commented Mar 30, 2018

@catamphetamine v1.1.6 works without any workaround! Thanks!

@edolix edolix closed this as completed Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants