简体   繁体   English

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

[英]Starter create-react-app with IE11 polyfill import still aborts in IE11

Using: react 16.8.6.使用:反应 16.8.6。 Working in: Dev Mode.工作于:开发模式。

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

2) cd my-app 2) cd my-app

3) add: import "react-app-polyfill/ie11"; 3)添加:导入“react-app-polyfill/ie11”; as the new first line in index.js作为 index.js 中新的第一行

4) do: npm start 4)做:npm start

5) In IE11 on Windows 10 it aborts with these in the console: 5) 在 Windows 10 上的 IE11 中,它在控制台中中止这些:

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

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

I have tried other polyfills:我尝试过其他 polyfill:

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

and

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

and

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

and

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

The location of the Syntax error changes, but it still happens.语法错误的位置发生了变化,但它仍然发生。

Works fine in all other browsers.在所有其他浏览器中都可以正常工作。

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"));

The abort happens immediately before the generated code ever loads.中止发生在生成的代码加载之前。 It gives the old 'White screen of death' in IE11.它在 IE11 中提供了旧的“死亡白屏”。

Can anyone share the magic to get the 16.8.6 starter app to work in IE11?任何人都可以分享让 16.8.6 入门应用程序在 IE11 中工作的魔力吗?

You can refer to the following steps to support IE11:支持IE11可以参考以下步骤:

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

Second, add import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable';其次,添加import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable'; at the first line in src/index.js.在 src/index.js 的第一行。

Third, add ie 11 in package.json like this:第三,在 package.json 中添加ie 11像这样:

在此处输入图片说明

Finally, you can restart your app and it will work in IE11.最后,您可以重新启动您的应用程序,它将在 IE11 中运行。 If it still doesn't work, delete the app and create it again according to the above steps.如果还是不行,请删除该应用程序,然后按照上述步骤重新创建。

As of late 2020, react-scripts 4.0.0 seems to be having issues with react-app-polyfill and IE 11, as detailed in https://github.com/facebook/create-react-app/issues/9906 .截至 2020 年底, react-scripts 4.0.0 似乎在react-app-polyfill和 IE 11 方面存在问题,详见https://github.com/facebook/create-react-app/issues/9906

My workaround, at the top of my index.js (multiple others shown in the link above)我的解决方法,在我的 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 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';

// ...

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

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