0

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"]
}
Ryan Cogswell
  • 75,046
  • 9
  • 218
  • 198
Avinash
  • 879
  • 2
  • 14
  • 26
  • What is `types.js`? – connexo Jan 16 '19 at 14:12
  • In most asset building stacks the `node_modules` folder is exempt from transpilation. `node_modules` / npm packages are expected to only deliver ES5 content, but some don't follow this. – connexo Jan 16 '19 at 14:13

1 Answers1

0

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.

connexo
  • 53,704
  • 14
  • 91
  • 128
  • Yes, It worked. I found out that I was excluding node_module for babel-loader in webpack.config file. I just removed that and its working fine .But don't know whether it will create any performance impact or not.Thanks – Avinash Jan 17 '19 at 08:58
  • Removing the exclude option is not a good idea, not only for performance reasons. I'd rather copy the file into a folder where it will be transpiled by default. – connexo Jan 17 '19 at 09:25
  • but copying from node_module and keeping it in my file will create difficulty when I will change work-space or someone else will checkout the code from repo. So I want to make that automated or excluding node_module and including only types.js folder inside webpack.config – Avinash Jan 17 '19 at 09:36