我正在使用react native实现firebase,这是我正在使用的版本
"firebase": "^5.4.1",
"react-native": "0.56.0",
"react": "16.4.1",
但是当我导入firebase时,它显示以下错误:
undefined is not a function (evaluating '_iterator2[typeof Symbol === "function" ? Symbol.iterator : "@@iterator"]()')
注意:仅在Android设备上获取此错误,在iOS上它是完美的。
我在导入firebase时遇到了同样的问题,并找到了解决方案here
在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');
我认为它的方式是某些JS语法不能很好地理解Android。
@Syph提供的解决方案对我来说还不够完美,我必须在“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');
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++],
}),
};
};
}
}
}
Android导入Firebase时可能无法理解这些JS语法。将这些代码添加到index.js可能会解决它。
注意:如果您有单独的index.android.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');
我尝试了最重要的解决方案,但解决了我的错误是遵循这些步骤:
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');
import './polyfills.js';
现在重新加载应用程序(按R两次)。希望它有效!