[英]Get application created using create-react-app working in IE11
I have created my React application using create-react-app version 3.3.0 .我使用create-react-app version 3.3.0创建了我的 React 应用程序。 My application works fine in all browsers except IE11.我的应用程序在除 IE11 之外的所有浏览器中都能正常工作。
The errors in the console is控制台中的错误是
HTML1300: Navigation occurred.
localhost:3000
SCRIPT1002: Syntax error
1.chunk.js (107,34)
SCRIPT1002: Syntax error
main.chunk.js (183,26)
I have seen many many posts about this and I believe I have followed all the steps that blogs/stackover flow posts say have to be done but nothing seems to fix my application.我看过很多关于这个的帖子,我相信我已经按照博客/stackover 流程帖子所说的所有步骤进行操作,但似乎没有任何东西可以修复我的应用程序。
My package.json contains, see it contains IE11 in the browser list我的 package.json 包含,在浏览器列表中看到它包含 IE11
"dependencies": {
"prop-types": "^15.7.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"react-router-dom": "~5.1.2",
"react-scripts": "~3.2.0"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^2.5.1"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
My "index.jsx" contains我的“index.jsx”包含
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import ComponentA from './components/ComponentA';
import ComponentB from './components/ComponentB';
render(
(
<Router >
<Layout>
<Switch>
<Route exact path="/" component={ComponentA} />
<Route exact path="/b" component={ComponentB} />
</Switch>
</Layout>
</Router>
),
document.getElementById('root'),
);
I run my application by doing the following我通过执行以下操作来运行我的应用程序
Fix Attempt 1: react-app-polyfill修复尝试 1:react-app-polyfill
package.json package.json
npm install react-app-polyfill
It is added to "package.json" as a dependency它作为依赖项添加到“package.json”
"dependencies": {
.....
"react-app-polyfill": "^1.0.6",
....
},
index.jsx索引.jsx
In index.jsx I added the following imports as the FIRST imports在 index.jsx 中,我添加了以下导入作为 FIRST 导入
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
Result结果
IE still shows a blank page and the same error in the console IE 仍然在控制台中显示空白页和相同的错误
Fix Attempt 2: @babel/polyfill修复尝试 2:@babel/polyfill
package.json package.json
npm install @babel/polyfill
It is added to "package.json" as a dependency它作为依赖项添加到“package.json”
"dependencies": {
.....
"@babel/polyfill": "^7.10.1",
....
},
index.jsx索引.jsx
In index.jsx I added the following imports as the FIRST imports在 index.jsx 中,我添加了以下导入作为 FIRST 导入
import '@babel/polyfill';
Result结果
IE still shows a blank page and the same error in the console IE 仍然在控制台中显示空白页和相同的错误
Fix Attempt 3: core-js修复尝试 3:core-js
package.json package.json
npm install core-js
It is added to "package.json" as a dependency它作为依赖项添加到“package.json”
"dependencies": {
.....
"core-js": "^3.6.4",
....
},
index.jsx索引.jsx
In index.jsx I added the following imports as the FIRST imports在 index.jsx 中,我添加了以下导入作为 FIRST 导入
import 'core-js';
I also tried我也试过
import 'core-js/stable';
Result结果
IE still shows a blank page and the same error in the console IE 仍然在控制台中显示空白页和相同的错误
NOTE笔记
When I tried each option I did the following当我尝试每个选项时,我做了以下
What am I doing wrong that all the fixes mentioned in other posts/blogs are not working for me.我做错了什么,其他帖子/博客中提到的所有修复都对我不起作用。
Strangely i now have this working, I am not sure what I changed to get it working.奇怪的是我现在有这个工作,我不确定我改变了什么让它工作。 However this is what i currently have.然而,这是我目前拥有的。
package.json package.json
"dependencies": {
"prop-types": "^15.7.2",
"react": "^16.11.0",
"react-app-polyfill": "^1.0.6",
"react-dom": "^16.11.0",
"react-masonry-component": "^6.2.1",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.2.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"ie 11"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11"
]
}
index.jsx索引.jsx
// these 2 MUST be the first 2 imports
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.