-1

I have react-hooks app built with react-router, redux, webpack4, babel. and I can not get react app renders on IE browser.

I guess it's an issue with transpiling es6 to es5.

Here's things that I have tried. None of them worked though.

index.html

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-sham.min.js"></script>

index.js imported 'core-js' or 'react-app-polyfill' at the very time of the index fild.

import 'core-js';
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/ie11';

babel.js add targets options to env.

presets: [
    [
      'env',
      {
        useBuiltIns: 'entry',
        targets: {
          browsers: [
            'last 1 version',
            '> 1%',
            'not dead',
            'ie >= 9'
          ],
          uglify: true,
        },
        loose: true,
        modules: isTest ? 'commonjs' : false,
        debug: isTest ? false : true,
      },
    ],
    'react',
  ],
plugins: [
    'transform-runtime',
    'transform-class-properties',
    'transform-object-rest-spread',
    'syntax-dynamic-import',
]

package.json

"browserslist": [
    "last 1 version",
    "> 1%",
    "not dead",
    "ie >= 9"
  ],

webpack.base.js add browsers option to 'postcss-loader, autoprefixer'.

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        use: [
          {
            loader: 'babel-loader',
            options: babelConfig,
          },
        ],
      },
      {
        test: /\.(sa|sc|c)ss$/,
        exclude: /node_modules/,
        use: [
          {
            loader: devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
          },
          {
            loader: 'css-loader',
            options: {
              minimze: true,
              sourceMap: devMode,
              importLoaders: 1,
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              indent: 'postcss',
              plugins: [
                autoprefixer({
                  browsers: ['last 1 version',
                             '> 1%',
                             'not dead',
                             'ie >= 9'
                  ],
                }),
              ],
              sourceMap: devMode,
            },
          },
          {
            loader: 'sass-loader',
            options: {
              sourceMap: devMode,
              includePaths: ['client/styles/main.scss'],
            },
          },
        ],
      },
    ],
  },
 ...
  },

versions

"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^4.3.1",
"connected-react-router": "^6.4.0",
"react-redux": "^6.0.0",
"webpack": "^4.16.5",
"babel-core": "^6.26.3",
"core-js": "^2.5.7",
"react-app-polyfill": "^1.0.2",

------------------------------- EDITION ---------------------------------

UPDATE : added error message in IE browser and created code Sandbox.

error message

code sandbox link

------------------------------- EDITION ---------------------------------

After having updated to the latest IE version. I am getting a Back navigation caching error and JS syntax error in vendors.lazy-chunk.js.

------------------------------- EDITION ---------------------------------

login feature code sample update. code sample

Jiaah
  • 758
  • 2
  • 11
  • 29
  • Can you create a Code Sandbox (https://codesandbox.io/s/new) to show us exactly what you're talking about. Errors in compiling code from ES6+ down to ES5 will depend on the specific function being used. – technicallynick Aug 15 '19 at 02:51
  • What error are you getting? – Arye Eidelman Aug 15 '19 at 03:49
  • There must be an error in the console for IE, please check it, and update your question with that. – Alejandro Garcia Anglada Aug 15 '19 at 06:33
  • Have you used F12 dev tools to check if there's any error in console in IE? We can't reproduce the issue with only the above code snippet. Could you please provide a minimal,reproducible sample with CodeSandbox or StackBlitz(https://stackblitz.com/)? So that we'll have a better understanding of the issue. Besides, you could refer to [this thread](https://stackoverflow.com/questions/56435589/starter-create-react-app-with-ie11-polyfill-import-still-aborts-in-ie11/) about supporting IE11 in react app. – Yu Zhou Aug 15 '19 at 07:11
  • CodeSandbox couldn't run in IE 11, so I made a demo using your code in StackBlitz: https://stackblitz.com/edit/react-vhafos. The app seems run well in IE 11: https://react-vhafos.stackblitz.io/. You could compare with the dependencies in the demo to see if you missed some dependencies. And what version of IE are you using? The error occurs in your console shows that there's something wrong with the F12 dev tool. Please move to the latested version of IE and try it again. You could also refer to [this thread](https://stackoverflow.com/questions/28301393/an-error-has-ocurredjsplugin-3005). – Yu Zhou Aug 19 '19 at 09:42
  • I have all dependencies and have updated IE to the latest version. Now I am getting more specific error which I am still not able to solve it. – Jiaah Aug 19 '19 at 15:00
  • Thanks for taking your time to help me, @YuZhou. – Jiaah Aug 19 '19 at 15:09

1 Answers1

0

I reproduced your code in my side and made it run without any error in IE 11. You could refer to my steps:

  1. Create a react app using create-react-app.

  2. I used the files in your CodeSandbox, and modified some of them.

(1) You could check my package.json.

(2) I also modified the index.js, we only need to add import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; at the first line of index.js to make it compatible with IE 11.

(3) I also modified import createBrowserHistory from "history/createBrowserHistory"; into import { createBrowserHistory } from 'history'; in store.js. Otherwise, it will throw the error "Warning: Please use require("history").createBrowserHistory instead of require("history/createBrowserHistory"). Support for the latter will be removed in the next major release."

  1. Install the following packages manually. Pay attention to that the webpack version is 4.39.1. In my case, I also installed node-sass:

enter image description here

  1. Run npm start to start the app. The screenshot in IE 11 is like this: https://i.stack.imgur.com/aTq5G.png.

You could also check my sample here: https://stackblitz.com/edit/react-vhafos.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Thanks for taking your time to answer my question @YuZhou. I've followed your answer and ensured to have the IE latest version. But It still fails. With just basic setup in stackblitz renders in my IE browser as well. but when i open my website with full code, it doesn't render. Would you please kindly check my original source code ? Your help will be greatly appreciated. – Jiaah Aug 25 '19 at 06:53
  • Let me know if you would check my repo, I will send you the link! Thank you @Yu Zhou – Jiaah Aug 25 '19 at 06:58
  • Hi @Jiah827, I think the error may caused by the other parts of the code. It would be better if you provide [a minimal,reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) instead of the whole source code. Besides, if you got syntax error with full code, I think the guess you put forward at first about issue with transpiling es6 to es5 might be right. You could also try to transpile es6 syntax in your code to es5 with [babel](https://babeljs.io/repl). – Yu Zhou Aug 26 '19 at 03:10
  • I don't have any syntax error on dev mode. I've updated code sample link. Thank you !! – Jiaah Aug 26 '19 at 07:59
  • So strange, still can't reproduce any error in prod mode (as well as in dev mode). I use `npm run build` to make it run on prod mode, you could check [the result](https://i.stack.imgur.com/Xu8ey.gif). I just replaced the files with those in your last edition and installed some needed packages. Besides, I moved the `assets` folder into the `src` and modified the path when using. You could check my [file catalog](https://i.stack.imgur.com/8vE34.png) and the [package.json](https://i.stack.imgur.com/XuYUL.png). – Yu Zhou Aug 27 '19 at 03:19
  • I will test it again tomorrow. I can't access window computer till tomorrow as mine is Mac OS. Thanks. Yu Zhou !! – Jiaah Aug 27 '19 at 09:38