简体   繁体   English

script1010:语法不明| 无法使用Babel for IE11将ES6转换为ES5

[英]script1010: unidentified syntax | Not Able to convert ES6 to ES5 using Babel for IE11

In my Reactjs code I am getting 在我的Reactjs代码中

Script1010: unidentified syntax. Script1010:语法不明。

This is coming because of types.min.js file inside node_module/types.js folder. 这是由于node_module / types.js文件夹中的types.min.js文件而来的。

Inside types.min.js file; 内部types.min.js文件; o=function(...n) code is giving error because of ES6 syntax. 由于ES6语法, o=function(...n)代码出现错误。 And while I am building the code using Gulp, its not converting ES6 to ES5 so IE11 is throwing Error. 当我使用Gulp构建代码时,它没有将ES6转换为ES5,因此IE11抛出错误。 I am using babel-polyfill. 我正在使用babel-polyfill。

So any Clue why its not converting .??? 那么任何线索为什么它不转换。

While I am converting types.js code into ES5 format and pasting it to types.min.js file its working perfectly. 当我将types.js代码转换为ES5格式并将其粘贴到types.min.js文件中时,它的工作原理非常完美。 But its not the correct approach. 但这不是正确的方法。

main.js : main.js

// polyfills
   import 'classlist-polyfill';
   import 'element-closest';
   import objectFitImages from 'object-fit-images';
   import picturefill from 'picturefill';
   import 'masonry-layout/dist/masonry.pkgd';
   import 'imagesloaded/imagesloaded.pkgd';

babelrc : babelrc

{
  "presets": ["env","es2015", "react"],
  "plugins": [
    "transform-object-rest-spread",
    "transform-class-properties"]
}

If you copy https://raw.githubusercontent.com/phazelift/types.js/master/types.min.js to the IE 11 console and run it, you'll see the code you get from node_modules/types.js is not compatible with IE 11. 如果将https://raw.githubusercontent.com/phazelift/types.js/master/types.min.js复制到IE 11控制台并运行它,您将看到从node_modules/types.js获得的代码是与IE 11不兼容。

Because in most build stack configurations modules from the node_modules folder are exempt from transpilation with Babel, the easiest fix would be to copy their code into your project folders where your own JS code resides. 因为在大多数构建堆栈配置中,可以免除使用Babel node_modules文件夹中的模块,所以最简单的解决方法是将其代码复制到您自己的JS代码所在的项目文件夹中。 Importing it from there makes sure your Babel transpiles the code. 从那里导入它可以确保您的Babel编译代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM