带有 IE11 polyfill 导入的 Starter create-react-app 仍然在 IE11 中中止

IT技术 reactjs internet-explorer-11
2021-03-27 01:31:19

使用:react 16.8.6。工作于:开发模式。

1) 做: npm create-react-app my-app

2) cd 我的应用程序

3)添加:导入“react-app-polyfill/ie11”;作为 index.js 中新的第一行

4)做:npm start

5) 在 Windows 10 上的 IE11 中,它在控制台中中止这些:

SCRIPT1002:语法错误 1.chunk.js (10735,34)

SCRIPT1002:语法错误 main.chunk.js (154,1)

我尝试过其他 polyfill:

导入“react-app-polyfill/ie9”;

导入'react-app-polyfill/stable';

导入'react-app-polyfill/ie9';导入'react-app-polyfill/stable';

导入'react-app-polyfill/ie11';导入'react-app-polyfill/stable';

语法错误的位置发生了变化,但它仍然发生。

在所有其他浏览器中都可以正常工作。

import "react-app-polyfill/ie11";
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import "bootstrap/dist/css/bootstrap.css";

ReactDOM.render(<App />, document.getElementById("root"));

中止发生在生成的代码加载之前。它在 IE11 中提供了旧的“死亡白屏”。

任何人都可以分享让 16.8.6 入门应用程序在 IE11 中工作的魔力吗?

3个回答

支持IE11可以参考以下步骤:

首先,安装包:npm install react-app-polyfill.

其次,import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable';在 src/index.js 的第一行添加

第三,ie 11像这样添加package.json: 

在此处输入图片说明

最后,您可以重新启动您的应用程序,它将在 IE11 中运行。如果还是不行,请删除该应用程序,然后按照上述步骤重新创建。

做到了!太感谢了!我们缺少 BROWSERLIST 信息。如此接近但如此遥远......结果我太新了,无法支持这个完美的答案。如果其他可以投票的人会这样做!
2021-05-24 01:31:19

截至 2020 年末,react-scripts4.0.0 似乎react-app-polyfill与 IE 11存在问题,详见https://github.com/facebook/create-react-app/issues/9906

我的解决方法,在我的 index.js 顶部(上面链接中显示了多个其他)

// https://github.com/facebook/create-react-app/tree/master/packages/react-app-polyfill
import 'react-app-polyfill/ie11'
// https://github.com/facebook/create-react-app/issues/9906
// this is currently borked -> import 'react-app-polyfill/stable'
// so use core-js.. which might be the "right" way now per
// https://reactjs.org/docs/javascript-environment-requirements.html
import 'core-js/stable'

https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md

yarn add react-app-polyfill

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

// ...