ReactJS:未捕获的ReferenceError:未定义Set

问题描述 投票:8回答:2

在某些浏览器上我只能得到

未捕获的ReferenceError:未定义Set。

它是使用create-react-app创建的reactjs应用程序。

为什么我仍然得到错误? 我如何使用polyfill? 反应是否默认使用polyfill?

webpack.config.prod.js

entry: [require.resolve('./polyfills'), paths.appIndexJs],

polyfills.js

'use strict';

if (typeof Promise === 'undefined') {
  // Rejection tracking prevents a common issue where React gets into an
  // inconsistent state due to an error, but it gets swallowed by a Promise,
  // and the user has no idea what causes React's erratic future behavior.
  require('promise/lib/rejection-tracking').enable();
  window.Promise = require('promise/lib/es6-extensions.js');
}

// fetch() polyfill for making API calls.
require('whatwg-fetch');

// Object.assign() is commonly used with React.
// It will use the native implementation if it's present and isn't buggy.
Object.assign = require('object-assign');

// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
// We don't polyfill it in the browser--this is user's responsibility.
if (process.env.NODE_ENV === 'test') {
  require('raf').polyfill(global);
}
javascript reactjs
2个回答
8
投票

不确定是否有人找到了正确的解决方案。但是对于较旧的浏览器,特别是在Android Kitkat 4.4浏览器/ webview上,这个问题非常明显。请使用以下链接获取解决方案

https://reactjs.org/docs/javascript-environment-requirements.html

如果您使用的是ReactJS 16,那么首先要包含babel-polyfill

  • npm install --save babel-polyfill

打开index.js并导入babel-polyfill

  • 进口'babel-polyfill'

创建构建和部署。这应该可以解决问题。


0
投票

似乎是一个问题with older WebView不支持ES6。 我在Genymotion(Android API 21)上遇到了这个问题,即使在更新Chrome之后,它在某种程度上也无法正常工作。 但它适用于物理设备。

© www.soinside.com 2019 - 2024. All rights reserved.