React 应用程序在 IE 11 浏览器中不起作用

Lor*_*ran 5 polyfills internet-explorer-11 reactjs create-react-app

我在这里看到了很多类似的问题,我已经尝试了所有方法,但我不知道为什么仍然没有显示任何内容。

  1. npm install react-app-polyfill

  2. 我在 package.json 的生产和开发数组中添加了“ie 11”

  3. 将此两行添加import "react-app-polyfill/ie11"; import "react-app-polyfill/stable";到顶部index.js

  4. 删除 node_modules 中的 .cache 文件夹

  5. 重启应用

但仍然没有在 ie 11 中显示任何内容。

这是我的 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"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我什至删除了 node_modules 文件夹并npm重新安装,但仍然无法正常工作。

更新

我在 IE 11 中收到两条错误消息。

SCRIPT5022: SyntaxError
File: 0.chunk.js, Line: 176128, Column: 38
Run Code Online (Sandbox Code Playgroud)

SCRIPT5022: The error you provided does not contain a stack trace.
File: 0.chunk.js, Line: 205780, Column: 64
Run Code Online (Sandbox Code Playgroud)

.

Yu *_*hou 6

你的react-scripts版本是什么?这似乎是react-scripts3.3.0 版的问题。您可以在 GitHub 中找到问题报告:issue 1 , issue 2

它仍然可以与react-scripts@3.2.0. 您可以尝试恢复到 3.2.0 作为解决方法。还请记住删除.cache文件夹node_modules并删除IE浏览器缓存,然后重试。


Yug*_*thi 0

我刚刚在 Edge 浏览器上进行了测试,npm start给出了与您提到的相同的错误,但您说您只想在 ie11 上运行您的应用程序。我这样做了,并通过包装(之后)npm run build提供了它,它工作正常。除非您想在 ie 中进行开发,否则如果您能够在本地 ie 上运行您的应用程序,我想这会有所帮助。servenpm i -g serve