简体   繁体   English

React 生产版本不适用于 IE 11

[英]React production build not working with IE 11

My react project is using express as backend.我的反应项目使用 express 作为后端。 When I am running project in development mode using "npm start" for React and "node server.js" for express server I am able to use it in chrome as well as in IE 11. When I am creating production build using "npm run build" and running it using "node server.js" it works in Chrome but in IE 11 its not working.当我在开发模式下使用 React 的“npm start”和 Express 服务器的“node server.js”运行项目时,我可以在 chrome 和 IE 11 中使用它。当我使用“npm run”创建生产构建时build”并使用“node server.js”运行它,它在Chrome中工作,但在IE 11中不起作用。 I dont see any error in console.我在控制台中没有看到任何错误。

I am using below statements at start of index.js to make code IE 11 compatible.我在 index.js 开头使用以下语句来使代码与 IE 11 兼容。

import 'core-js/es6/map';导入 'core-js/es6/map'; import 'core-js/es6/set';导入 'core-js/es6/set'; import 'raf/polyfill';导入 'raf/polyfill';

React version - 16. Project created using create-react-app. React 版本 - 16. 使用 create-react-app 创建的项目。

I think it is not working because webpack.config.prod.js is not bundling IE 11 compatible code.我认为它不起作用,因为 webpack.config.prod.js 没有捆绑 IE 11 兼容代码。

you should use : react-app-polyfill你应该使用:react-app-polyfill

This package includes polyfills for various browsers.该软件包包括适用于各种浏览器的 polyfill。 It includes minimum requirements and commonly used language features used by Create React App projects.它包括 Create React App 项目使用的最低要求和常用语言功能。

Usage First, install the package using Yarn or npm:用法 首先,使用 Yarn 或 npm 安装包:

npm install react-app-polyfill

or或者

yarn add react-app-polyfill

For IE9:对于 IE9:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';

For IE11:对于 IE11:

// These must be the first lines in src/index.js
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';

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. React 支持所有流行的浏览器,包括 Internet Explorer 9 及更高版本,尽管旧版浏览器(例如 IE 9 和 IE 10)需要一些 polyfill。

Install these two packages.安装这两个包。

  npm install babel-polyfill
  npm install react-app-polyfill

This must be the first line in src/index.js这必须是 src/index.js 的第一行

import "react-app-polyfill/ie9"
import "react-app-polyfill/ie11"
import "react-app-polyfill/stable"
import 'raf/polyfill';

You can also configure your manifest to handle different browsers, using the following doc : https://github.com/browserslist/browserslist您还可以使用以下文档配置您的清单以处理不同的浏览器: https : //github.com/browserslist/browserslist

example :例子 :

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

import "react-app-polyfill/ie11"导入“react-app-polyfill/ie11”

import "react-app-polyfill/stable"导入“react-app-polyfill/stable”

The second line(react-app-polyfille/stable) did the trick for me.第二行(react-app-polyfille/stable)对我有用。 I was trying to load a react page in a desktop application which uses ie11 to render pages我试图在使用 ie11 呈现页面的桌面应用程序中加载反应页面

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

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