如何使我的React应用程序在Edge和IE 11上运行? [英] How do I make my React app work on Edge and IE 11?

查看:257
本文介绍了如何使我的React应用程序在Edge和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 11last 1 edge
  • index.js
  • 中导入了react-app-polyfill/stablereact-app-polyfill/ie11
  • 已删除node_modules/.cache
  • Installed react-app-polyfill
  • Updated my browser list in package.json to include ie 11 and last 1 edge
  • imported react-app-polyfill/stable and react-app-polyfill/ie11 in index.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执行maplength.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆