React, WebPack and Babel for Internet Explorer 10 and below produces SCRIPT1002: Syntax error

前端 未结 2 1521
花落未央
花落未央 2021-01-19 05:31

I\'ve read multiple threads regarding similar issues and tried some propositions, but had no results.

I\'ve followed few tutorials related to React.js

相关标签:
2条回答
  • 2021-01-19 05:50

    Simply add devtools : "source-map" to your Webpack config like this:

    const path = require('path');
    module.exports = {
      devtool: "source-map",
      entry: ['babel-polyfill', path.resolve(__dirname, './js/main.js')],
      mode: 'production',
      output: {
        path: __dirname+'/js/',
        filename: 'main-webpack.js'
      }
    };
    

    This will remove eval and change your source map to be supported by IE.

    UPDATE I've changed devtool to inline-cheap-module-source-map and got error point to overlay.js -> const ansiHTML = require('ansi-html');

    And to support ES6 syntax you have to compile your JavaScript code with Babel.

    0 讨论(0)
  • 2021-01-19 06:06

    In your package.json file

    change the version of webpack-dev-server to version "2.7.1" (or earlier).

    "webpack-dev-server": "2.7.1"
    

    Then do a npm install et voilà.

    That solved the problem for me.

    All versions after 2.7.1 gives me an error similar to yours.

    0 讨论(0)
提交回复
热议问题