如何使我的React应用程序在Edge和IE 11上运行? [英] How do I make my React app work on Edge and IE 11?
问题描述
我的反应一直很好,但是我决定在Edge和Chrome上尝试一下,并且在两种浏览器上加载时都出现语法错误.该应用程序是使用create-react-app编写的,当我发现它无法在Windows上运行时,我执行了以下操作:
My react has been working fine, but I decided to try it on Edge and Chrome and on both browsers I get a syntax error when it loads. The app was written using create-react-app, and when I discovered it wasn't working on Windows, I did the following:
- 已安装
react-app-polyfill
- 在
package.json
中更新了我的浏览器列表,以包括ie 11
和last 1 edge
- 在
index.js
中导入了 - 已删除
node_modules/.cache
react-app-polyfill/stable
和react-app-polyfill/ie11
- Installed
react-app-polyfill
- Updated my browser list in
package.json
to includeie 11
andlast 1 edge
- imported
react-app-polyfill/stable
andreact-app-polyfill/ie11
inindex.js
- Deleted
node_modules/.cache
并重新启动npm start
,但是Edge和IE 11开发工具控制台均显示语法错误:
但由于某些奇怪的原因,它们显示不同的行号.无奈之下,我还尝试删除所有node_modules
并再次运行npm install
.仍然没有帮助.
and restarted npm start
but both Edge and IE 11 dev tools console show syntax errors:
but they show different line numbers for some odd reason. In desperation, I also tried deleting all of node_modules
and running npm install
again. Still no help.
如果我进行生产构建并提供服务,则某些页面似乎可以工作,而另一些页面则在IE和Edge中出现错误,抱怨尝试对null执行map
或length
.
If I do a production build and serve, some pages seem to work and others I get errors in IE and Edge complaining about trying to do map
or length
on nulls.
推荐答案
react-scripts
3.3.0及更高版本似乎是一个问题.您可以在GitHub中找到许多问题报告,例如: github.com/facebook/create-react-app/issues/8197 , github.com/facebook/create-react-app/issues/8195 .
It seems to be an issue with react-scripts
version 3.3.0 and higher. You could find many issue reports in GitHub, for example: github.com/facebook/create-react-app/issues/8197, github.com/facebook/create-react-app/issues/8195.
它仍然可以与react-scripts@3.2.0
一起使用.您可以尝试恢复到3.2.0作为解决方法.
It can still work with react-scripts@3.2.0
. You could try to revert back to 3.2.0 as a workaround.
这篇关于如何使我的React应用程序在Edge和IE 11上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!