使用polyfills的IE11中出现SCRIPT1002 / 1010错误

时间:2018-12-27 15:12:42

标签: reactjs typescript webpack babel

我正在使用Typescript + React + Webpack堆栈(对于ts / tsx文件,我有awesome-typescript-loader)。我试图在IE11上运行我的应用程序,但在IE调试器中遇到问题。

调试器显示SCRIPT1002 @第一行,并且该行带有箭头功能。我通过添加来处理它:

require('@babel/plugin-proposal-object-rest-spread');
require('@babel/plugin-transform-arrow-functions');
require('@babel/plugin-proposal-class-properties');

到配置目录中的polyfills.js文件。我的webpack.config.prod.js包含:

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

和polyfills.js:

require('@babel/plugin-proposal-object-rest-spread');
require('@babel/plugin-transform-arrow-functions');
require('@babel/plugin-proposal-class-properties');

'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);
}

在此SCRIPT1002之后,出现图像上的SCRIPT1010错误: https://i.imgur.com/9voXrwO.png

,我卡住了。有什么想法吗?

0 个答案:

没有答案