我今天使用 create-react-app 创建了一个新项目。生产版本在 IE11 上运行不佳,控制台显示以下错误:
SCRIPT1010: Expected identifier
它在我的 main.js 中指向的行:
{var n=e&&e.__esModule?function(){return e.default}:function(){return e};
错误出现在上面的 e.(默认)之后。我的包 json 很简单:
{
"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 上也运行良好。我需要有polyfills吗?
最佳答案
这是我修复它的方法。不要忘记 React 先生“Dan Abramov”在这方面帮助了我。
所以问题是默认情况下应用程序是在 IE7 上呈现的,而不仅仅是支持转译版本的 IE IE11/EDGE。所以我不得不提及元信息,让浏览器知道目标浏览器是 IE11/edge。将其添加到 index.html 的 head
部分:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
现在,据我所知,您还会在控制台中看到一些错误,内容如下:
SCRIPT5009: 'Set' is undefined
不用担心,还有一种解决方法:https://reactjs.org/docs/javascript-environment-requirements.html
这是我在 git 上与 Dan 讨论的问题:https://github.com/facebook/create-react-app/issues/4255
关于ReactJS-SCRIPT1010 : Expected identifier - Production build not running on IE11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49649831/