question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Internet Explorer ES6 function not compiled

See original GitHub issue

Describe the bug Internet Explorer ES6 function not compiled, which comes from socket.io-parser module a dependency of socket.io-client.

Capture d’écran 2021-04-01 à 08 31 51

I have been trying to force the compilation for this specific module, but babel-loader can’t reach it because I am not making a straight ES6 import of socket.io-parser in my pages. import parser from 'socket.io-parser' otherwise I would have compiled this module easily 😃 But I need you to do it for me. And get a top notch module 🥇

function excludeNodeModulesExcept(modules) {
  var pathSep = path.sep
  if (pathSep == '\\')
    // must be quoted for use in a regexp:
    pathSep = '\\\\'
  var moduleRegExps = modules.map(function(modName) {
    return new RegExp('node_modules' + pathSep + modName)
  })

  return function(modulePath) {
    if (/node_modules/.test(modulePath)) {
      for (var i = 0; i < moduleRegExps.length; i++) if (moduleRegExps[i].test(modulePath)) return false
      return true
    }
    return false
  }
}

webpackRule = [
    {
      test: /\.(js|jsx|ts|tsx)$/,
      exclude: excludeNodeModulesExcept(['query-string', 'socket.io-parser']),
      loader: 'babel-loader'
    }
]

Expected behavior I want the javascript bundles to run on Internet Explorer 11, as simple as that.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
markvandenbrinkcommented, Apr 30, 2021

Hi there,

I’ve run into the same issue. But the solution is quite simple. Webpack uses the ES6 build, and by adding a browser field to the exports field in package.json this can be solved. Created a PR for this.

In the meantime, you can use the following workaround by adding an alias to your webpack.config.js:

resolve: {
  alias: {
    "socket.io-client": path.resolve(__dirname, "node_modules/socket.io-client/dist/socket.io.js"),
  },
},

Hope this helps!

0reactions
darrachequesnecommented, Apr 5, 2021

Please use babel to transpile the code to ES5/ES3. This is the best tool for this job.

More information here: https://github.com/sindresorhus/ama/issues/446

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES6 arrow (=>) functions incompatible with IE? - Stack Overflow
No, arrow functions aren't supported in IE. Use Babel to compile ES6 code to ES5. – 4castle. Dec 8, 2016 at 17:50.
Read more >
Module Methods - webpack
This section covers all methods available in code compiled with webpack. ... ES6 module syntax natively, meaning you can use import and export...
Read more >
Going from JavaScript to WebAssembly in three steps
Written in ES6 JavaScript (or ECMAScript 6, the latest version of JavaScript), it still compiles to ES5 to support Internet Explorer 11.
Read more >
BabelJS - Quick Guide - Tutorialspoint
We have used the ES6 Arrow function; the same does not work on all browsers as seen above. To get this working, we...
Read more >
When can I actually use ES6? - Marius Gundersen
TL;DR ES6 modules can be compiled to ES5 code in the browser. As long as a browser implements modules, it can compile the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found