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

标签 javascript reactjs webpack internet-explorer-11 babeljs

所以我正在使用我的同事在 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?

最佳答案

可能您需要引用 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

关于javascript - NPM 模块导致 Web 应用程序无法在 IE11 上呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52412754/

相关文章:

javascript - webpack css背景图片不显示?

javascript - 使用 webpack-dev-server 时 webpack 构建中缺少 bundle.js

javascript - 不变违规 : Element type is invalid: expected a string (built-in components) or a class/function (composite components) but got: object

javascript - 如何使用 selectmenu() UI 在打开菜单之前禁用选项?

reactjs - 每次选择/取消选择一行时,如何避免 react 原生 FlatList 重新渲染

javascript - 如何向 Material-UI 的 AppBar 组件添加多个元素?

javascript - react + 助焊剂 : Getting initial state into a store

Javascript 超时延迟

javascript - .split (",")仅每第 4 项?

javascript - 按类名搜索并查找 DIV 的内容