Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why IE 11 display blank page rendering react app

I have an issue with IE 11 and my react app. I use Webpack, babel and polyfill.io cdn and all is nice until rendering bundeled file, then it stops doing anything. Do you have any idea what may go wrong?

Thanks in advance.

like image 924
itgirl1234 Avatar asked Dec 05 '18 12:12

itgirl1234


People also ask

Does react work with IE11?

Supported Browsers​ By default, the generated project supports all modern browsers. Support for Internet Explorer 9, 10, and 11 requires polyfills. For a set of polyfills to support older browsers, use react-app-polyfill.

How do I show react project in browser?

Run the React Application Now you are ready to run your first real React application! A new browser window will pop up with your newly created React App! If not, open your browser and type localhost:3000 in the address bar.


2 Answers

React is not compatible right away with IE,

From the official documentation :

React supports all popular browsers, including Internet Explorer 9 and above, although some polyfills are required for older browsers such as IE 9 and IE 10.

We don’t support older browsers that don’t support ES5 methods, but you may find that your apps do work in older browsers if polyfills such as es5-shim and es5-sham are included in the page. You’re on your own if you choose to take this path.


To make your application work on IE (11 or 9) you will have to install React-app-polyfill :

https://www.npmjs.com/package/react-app-polyfill

Features :

Each polyfill ensures the following language features are present:

Promise (for async / await support) window.fetch (a Promise-based way to make web requests in the browser) Object.assign (a helper required for Object Spread, i.e. { ...a, ...b }) Symbol (a built-in object used by for...of syntax and friends) Array.from (a built-in static method used by array spread, i.e. [...arr]) 

Usage

First, install the package using Yarn or npm:

npm install react-app-polyfill 

Now, you can import the entry point for the minimal version you intend to support. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.

Internet Explorer 9

// This must be the first line in src/index.js import 'react-app-polyfill/ie9';  // ... 

Internet Explorer 11

// This must be the first line in src/index.js import 'react-app-polyfill/ie11';  // ... 

You can also configure your manifest to handle different browsers, using the following doc : https://github.com/browserslist/browserslist

example :

"browserslist": [     ">0.2%",     "not dead",     "ie >= 9" ] 

More information from the official site

like image 115
Treycos Avatar answered Sep 22 '22 23:09

Treycos


The package react-app-polyfill will help to work react app in ie9 & ie11. This will work both in development and production environment.

Please follow the steps 1. Edit the index.js file and add the following lines at the very top of the file.

    import 'react-app-polyfill/ie9';     import 'react-app-polyfill/ie11';     import 'react-app-polyfill/stable'; 
  1. Edit the Package.json file and add "ie 11" in the development sections of the browserslist. The default prouduction list is quite generous and does include ie 11 already via the >0.2%

    "browserslist": { "production": [   ">0.2%",   "not dead",   "not op_mini all" ], "development": [   "last 1 chrome version",   "last 1 firefox version",   "last 1 safari version",   "ie 11" ] 

    }

  2. delete your entire node_modules folder

  3. run npm install to re-install the node_modules

  4. run npm start to run again

like image 36
Rayees Pk Avatar answered Sep 19 '22 23:09

Rayees Pk