NPM模块导致Web应用程序无法在IE11上呈现

时间:2018-09-19 19:10:49

标签: javascript reactjs webpack internet-explorer-11 babel

所以我正在使用我的同事在npm上发布的react组件。它在除IE11之外的所有浏览器上都能正常工作。我怀疑在webpack配置中我们忽略了某些东西,这导致整个应用程序无法呈现。没有错误消息,只是一个空白页面。

src / index.js文件如下:

Class MuiTable extends Component {
...
}
export default compose(withStyles(styles, { withTheme: true }(MuiTable);

这是webpack.config.js文件:

var path = require('path');
module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'index.js',
    libraryTarget: 'commonjs2'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        include: path.resolve(__dirname, 'src'),
        exclude: /(node_modules|bower_components|build)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env']
          }
        }
      }
    ]
  },
  externals: {
    'react': 'commonjs react'
  }
};

这是.bablerc:

{
  "presets": ["env"],
  "plugins": [
    "transform-object-rest-spread",
    "transform-react-jsx"
  ]
}

这是package.json:

{
  "name": "ez-mui-table",
  "version": "1.1.4",
  "description": "Component for simple and fast integration of Material UI tables.",
  "main": "build/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack --watch",
    "build": "webpack"
  },
  "author": "Daniel Kinsbursky",
  "license": "MIT",
  "peerDependencies": {
    "react": "^16.4.2",
    "react-dom": "^16.4.2"
  },
  "devDependencies": {
    "eslint-config-prettier": "^2.9.0",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "babel-runtime": "^6.26.0",
    "prettier": "1.14.2"
  },
  "dependencies": {
    "@material-ui/core": "^3.0.2",
    "@material-ui/icons": "^3.0.1",
    "lodash.get": "^4.4.2",
    "lodash.sortby": "^4.7.0",
    "prop-types": "^15.6.2",
    "react-scripts": "1.1.5",
    "recompose": "^0.30.0"
  }
}

为什么这在IE11上不起作用?

1 个答案:

答案 0 :(得分:2)

可能您需要引用polyfills.js才能使其与IE兼容。

您可以在这些导入中引用polyfills.js:

/* polyfills.js */

import 'core-js/fn/array/find';
import 'core-js/fn/array/includes';
import 'core-js/fn/number/is-nan';

确保您执行npm install core-js

另请参阅Best way to polyfill ES6 features in React app that uses create-react-app

相关问题