ReactJS-SCRIPT1010:预期标识符-生产版本未在IE11上运行 [英] ReactJS - SCRIPT1010: Expected identifier - Production build not running on IE11

查看:208
本文介绍了ReactJS-SCRIPT1010:预期标识符-生产版本未在IE11上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天用create-react-app创建了一个新项目.生产版本在IE11上运行不正常,控制台显示以下错误:

I created a new project with create-react-app today. The production build is not running fine on IE11, the console shows following error:

SCRIPT1010: Expected identifier

它指向我的main.js内部的行:

The line it points to inside my main.js:

{var n=e&&e.__esModule?function(){return e.default}:function(){return e};

错误在上面的e.(默认)之后.我的包json很简单:

The error is after the e.(default) above. My package json is plain:

{
  "name": "sample-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

奇怪的是,我的开发服务器可以在IE11上完美运行,因此问题仅在于生产版本.它也可以在Chrome上正常运行.我需要吃polyfill吗?

Strange enough, my dev server works perfectly on IE11 so issue is only with production build. It works well on Chrome as well. Is that I need to have polyfills?

推荐答案

这是我修复它的方法.不要忘了React先生"Dan Abramov"在这方面帮助了我.

Here is how I fixed it. Not to forget Mr React "Dan Abramov" helped me in this.

因此,默认情况下,问题是应用程序是在IE7上呈现的,而不仅仅是在支持已编译版本的IE IE11/EDGE上呈现.因此,我不得不提到元信息,以使浏览器知道预期的浏览器是IE11/edge.将其添加到index.html的head部分:

So the issue is by default the application was being rendered on IE7 that is not on only IE IE11/EDGE that support the transpiled build. So I had to mention the meta information to let browser know that the intended browser is IE11/edge. Add this in the head section of your index.html:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

现在,正如我所知,您还会在控制台中看到以下错误:

Now as I got, you ay also see some error in console that reads:

SCRIPT5009: 'Set' is undefined

不用担心,还有一种解决方法: https://reactjs .org/docs/javascript-environment-requirements.html

Not to worry, there is a way around that as well: https://reactjs.org/docs/javascript-environment-requirements.html

这是我与Dan在git上讨论的问题: https://github .com/facebook/create-react-app/issues/4255

Here is the issue I discussed with Dan on git: https://github.com/facebook/create-react-app/issues/4255

这篇关于ReactJS-SCRIPT1010:预期标识符-生产版本未在IE11上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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