简体   繁体   English

“react-app-polyfill”在 IE11 中不起作用

[英]"react-app-polyfill" doesn't work in IE11

My React App is not working on IE 11.我的 React 应用程序无法在 IE 11 上运行。
My client wants the app to work on at least ie11.我的客户希望该应用程序至少可以在 ie11 上运行。
So, i have to solve this error.所以,我必须解决这个错误。

I tried the official documentation from "react-app-polyfill".我尝试了“react-app-polyfill”的官方文档。 But it still doesn't work.但它仍然不起作用。
Please help me.请帮我。

src/index.jsx源代码/index.jsx

import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import { Provider } from 'react-redux';
import store from './store';

ReactDOM.render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
);

serviceWorker.unregister();

package.json包.json

  "dependencies": {
    ...
    "@types/jest": "^24.0.25",
    "@types/node": "^12.12.24",
    "@types/react": "^16.9.17",
    "@types/react-dom": "^16.9.4",
    "@types/react-redux": "^7.1.5",
    "@types/react-router-dom": "^5.1.3",
    "axios": "^0.19.0",
    "install": "^0.13.0",
    "node-sass": "^4.13.0",
    "npm": "^6.13.4",
    "react": "^16.12.0",
    "react-app-polyfill": "^1.0.5",
    "react-dom": "^16.12.0",
    "react-hotkeys": "^2.0.0",
    "react-redux": "^7.1.3",
    "react-router": "^5.1.2",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.3.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "typescript": "^3.7.4"
  },
...
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }

Perhaps the issue is related to the react-scripts version , you are using react-scripts 3.3.0 and higher.也许问题与react-scripts version有关,您使用的是 react-scripts 3.3.0 及更高版本。 You could check the package.json file to verify it.您可以检查 package.json 文件来验证它。

There are some thread reports this error in GitHub, you could refer to them, for example: github.com/facebook/create-react-app/issues/8197 , github.com/facebook/create-react-app/issues/8195 . GitHub中有一些线程报这个错误,你可以参考他们,例如 github.com/facebook/create-react-app/issues/8197,github.com/facebook/create-react-app/issues/8195 .

As a workaround, you could try to downgrade the react-scripts version.作为解决方法,您可以尝试降级 react-scripts 版本。 As far as I know, it can still work with react-scripts@3.2.0 .据我所知,它仍然可以与react-scripts@3.2.0一起使用。

After adding react-app-polyfill in your index.js , it will work for PROD env but you need to update your browserslist inside package.json for DEV env在您的index.js中添加react-app-polyfill后,它将适用于 PROD 环境,但您需要为 DEV 环境更新package.json中的browserslist列表

index.js索引.js

import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

import React from 'react';
import ReactDOM from 'react-dom';
.
.

package.json包.json

.
.
"browserslist": {
  "production": [
    ">0.2%",
    "not dead",
    "not op_mini all"
  ],
  "development": [
    "last 1 chrome version",
    "last 1 firefox version",
    "last 1 safari version",
    "not dead" // new line
  ]
},
.
.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 IE11 polyfill 导入的 Starter create-react-app 仍然在 IE11 中中止 - Starter create-react-app with IE11 polyfill import still aborts in IE11 React App - Bable Polyfill 无法正常工作 IE11 - React App - Bable Polyfill not working correctly IE11 React 应用程序在使用 react-app-polyfill 后不适用于 IE 7 和 8,但适用于 IE 9 及更高版本 - React app is not working on IE 7 and 8 after using react-app-polyfill but working for IE 9 and above Dom 解析在 IE11 中的 React App 上无法正常工作 - Dom parsing doesn't correctly work on React App in IE11 本地存储中的日期变量在IE11中不起作用 - Date variable in local storage doesn't work in IE11 在IE11中反应应用程序崩溃 - React app crashes in IE11 IE11:如何在 Internet Explorer 中的 React 中填充 `Array.values().next()`? - IE11: How to polyfill `Array.values().next()` in Internet explorer, in React? IE11:将 window.location.origin 复制到剪贴板无法正常工作 - IE11: Copying window.location.origin to clipboard doesn't work correctly 使用 react polyfills 但出现错误 Object 不支持 IE11 中的属性或方法“重复” - Using react polyfills but getting error Object doesn't support property or method 'repeat' in IE11 对象在 React 的 IE11 中不支持属性或方法“scrollBy” - Object doesn't support property or method 'scrollBy' in IE11 in React
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM