undefined is not a function (evaluating '_iterator2[typeof Symbol === "function"

Viewed 4238

I am implementing firebase with react native, here are the versions i am working with

"firebase": "^5.4.1",
"react-native": "0.56.0",
"react": "16.4.1",

But when i import firebase, it is showing following error :

undefined is not a function (evaluating '_iterator2[typeof Symbol === "function" ? Symbol.iterator : "@@iterator"]()')

enter image description here

Note : Getting this error only on Android device, on iOS it is working perfect.

4 Answers

I had the same issue when importing firebase and found the solution here

Add this in your index.js

// index.js
global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');
require('core-js/fn/map');
require('core-js/fn/set');
require('core-js/fn/array/find');

The way I see it is that there are certain JS syntaxes that doesn't translate well for android to understand.

I tried solutions of above all but what solved my error was following these steps:

  1. create a polyfills file code and put in a file named polyfills.js, at the same level with index.js (entry point of my react-native project)

  2. the code:

global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');
require('core-js/fn/map');
require('core-js/fn/set');
require('core-js/fn/array/find');
  1. On the first line within index.js file include the following code:
import './polyfills.js';

Now Reload the app(Press R twice). Hope It works!

Answer Reference

The solution provided by @Syph, is not enough for me to run perfectly, I have to add following in "index.js" and it works for me.

global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');
require('core-js/fn/map');
require('core-js/fn/set');
require('core-js/fn/array/find');

if (Platform.OS === 'android') {
    if (typeof Symbol === 'undefined') {
        if (Array.prototype['@@iterator'] === undefined) {
            Array.prototype['@@iterator'] = function () {
                let i = 0;
                return {
                    next: () => ({
                        done: i >= this.length,
                        value: this[i++],
                    }),
                };
             };
        }
    }
}

Maybe these JS syntaxes when importing firebase cannot be understood by Android. Adding these codes to your index.js might resolve it.

Note: If you are having separate index.android.js add these codes to that file.

global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');
require('core-js/fn/map');
require('core-js/fn/set');
require('core-js/fn/array/find');
Related