简体   繁体   中英

React app is not working in IE 11 browser

I have seen a lot of similar questions here and I have tried all the ways but I have no idea why still not showing anything.

  1. npm install react-app-polyfill

  2. I added "ie 11" to production and development array in package.json

  3. Add this two-line import "react-app-polyfill/ie11"; import "react-app-polyfill/stable"; to top of index.js

  4. delete .cache folder inside node_modules

  5. Restart App

But still not showing anything in ie 11.

Here is my package.json

{
  "name": "firealarm",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.3",
    "@testing-library/user-event": "^7.1.2",
    "antd": "^3.26.2",
    "axios": "^0.19.0",
    "core-js": "^3.6.1",
    "cors": "^2.8.5",
    "jspdf": "^1.5.3",
    "jspdf-autotable": "^3.2.11",
    "react": "^16.12.0",
    "react-app-polyfill": "^1.0.5",
    "react-dom": "^16.12.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.3.0"
  },
  "scripts": {
    "start": "set PORT=3006 && react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      "ie 11",
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I even remove the node_modules folder and install npm again but still not working.

Update

I got two error message in IE 11.

SCRIPT5022: SyntaxError
File: 0.chunk.js, Line: 176128, Column: 38

And

SCRIPT5022: The error you provided does not contain a stack trace.
File: 0.chunk.js, Line: 205780, Column: 64

.

What is your react-scripts version? It seems an issue with react-scripts version 3.3.0. You could find the issue report in GitHub: issue 1 , issue 2 .

It can still work with react-scripts@3.2.0 . You could try to revert back to 3.2.0 as a workaround. Please also remember to delete .cache folder in node_modules and delete IE browser cache then try again.

Go to > /node_modules/react-dev-utils/webpackHotDevClient.js:60; add slashes: true

Below is the code sample

{
// Connect to WebpackDevServer via a socket.
var connection = new WebSocket(
  url.format({
    protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',
    hostname: window.location.hostname,
    port: window.location.port,
    //Hardcoded in WebpackDevServer
    pathname: '/sockjs-node',
    slashes: true,
  })
);
}

I just tested on edge browser, npm start gives the same error you mentioned, but you say that you just want to run your app on ie11. I did npm run build and served it via serve package(after npm i -g serve ), it works fine. Unless until if you would like to development in ie, if you are able to run your app on ie locally that will help I guess.

在 .bablerc 或 babel-config {loose:true} 中添加 @babel/preset-env 它对我有用

"@babel/preset-env": { "targets":">0.2%, not dead","loose":true}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM