Add babel polyfill to React Native Project

2019-05-01 07:33发布

问题:

I´m having a issue on android. Got this error:

undefined is not a function(evaluating '_iterator2typeof Symbol==='function'?Symbol.iterator:'@@iterator'´)

I think it is related to the use of for of, es6.

Can i add babel-polyfill to React Native Project ?

回答1:

In order to add babel-polyfill to your react-native project after installing

npm install --save babel-polyfill

just import it like this in your entry endpoint:

import 'babel-polyfill';

Now you can use new built-ins like Promise or WeakMap, static methods like Array.from and instance methods like Array.prototype.includes, etc.



回答2:

You can use

npm install es6-symbol --save

Then add in your index.android.js & index.ios.js

import 'es6-symbol/implement'