简体   繁体   中英

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

In my Reactjs code I am getting

Script1010: unidentified syntax.

This is coming because of types.min.js file inside node_module/types.js folder.

Inside types.min.js file; o=function(...n) code is giving error because of ES6 syntax. And while I am building the code using Gulp, its not converting ES6 to ES5 so IE11 is throwing Error. I am using 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. But its not the correct approach.

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 :

{
  "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.

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. Importing it from there makes sure your Babel transpiles the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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