使用:反应16.8.6。 正在使用:开发模式。
1)做:npm create-react-app my-app
2)cd my-app
3)添加:导入“ react-app-polyfill / ie11”;作为index.js中的新第一行
4)做:npm开始
5)在Windows 10的IE11中,它会在控制台中终止:
SCRIPT1002:语法错误 1.chunk.js(10735,34)
SCRIPT1002:语法错误 main.chunk.js(154,1)
我尝试了其他polyfills:
导入“ 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中运行的魔力?
答案 0 :(得分:2)
您可以参考以下步骤来支持IE11:
首先,安装软件包:npm install react-app-polyfill
。
第二,在src / index.js的第一行添加import 'react-app-polyfill/ie11'; import 'react-app-polyfill/stable';
。
第三,像这样在packge.json中添加ie 11
:
最后,您可以重新启动应用程序,它将在IE11中运行。如果仍然无法使用,请删除该应用,然后按照上述步骤重新创建。
答案 1 :(得分:0)
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';
// ...
答案 2 :(得分:0)
截至2020年末,react-scripts
4.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'