Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which browsers support import and export syntax for ECMAScript 6?

I am currently writing a web application using the MEAN Stack, and am attempting to write code in ECMAScript 6 JavaScript; however, I am getting errors in both Chrome and Firefox when using import and export syntax. Are there currently any browsers that fully support ECMAScript 6?

Please note: I am not asking when ECMAScript 6 will be supported by browsers. I'm asking which browsers support ECMAScript 6 import and export syntax. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla#Features_not_yet_supported_by_Firefox

like image 313
Gregory R. Avatar asked Nov 04 '15 08:11

Gregory R.


People also ask

How do I use ECMAScript 6 in browser?

You can enable experimental ECMAScript features in your browser by going to chrome://flags/#enable-javascript-harmony and enabling the JavaScript Harmony flag. For some features, you may have to use Chrome Canary with the JavaScript Harmony flag enabled.

Do browsers support ES6 modules?

Safari, Chrome, Firefox and Edge all support the ES6 Modules import syntax.

What percentage of browsers support ES6?

As ES6 refers to a huge specification and browsers have various levels of support, "Supported" means at least 95% of the spec is supported.

What is ECMAScript 6?

ECMAScript 6 is also known as ES6 and ECMAScript 2015. Some people call it JavaScript 6. This chapter will introduce some of the new features in ES6.

What is ES6 import and export in JavaScript?

ES6 | Import and Export. The ES6 is a JavaScript standard. With the help of ES6, we can create modules in JavaScript. In a module, there can be classes, functions, variables, and objects as well. To make all these available in another file, we can use export and import.

What is the import and export syntax in JavaScript?

Basically the import and export syntax is used everywhere where we write JavaScript and then transcompile and bundle it to “old-school” javascript. But the time when it can only be used in conjunction with compilers like Babel is over. Meanwhile Node.js also supports the so-called ES6 modules, and in the browser we can use them if we want to.

Which browsers support ES6?

Browser Support for ES6 (ECMAScript 2015) Safari 10 and Edge 14 were the first browsers to fully support ES6:


2 Answers

It's supported in:

  • Safari 10.1
  • Chrome 61
  • Firefox 54 – behind the dom.moduleScripts.enabled setting in about:config.
  • Edge 16
like image 109
Ali Avatar answered Oct 11 '22 14:10

Ali


Chrome and Firefox support import and export syntax (there exists tests for proper parsing).

What isn't supported is module loading - you can't load module by any means, because specification for it isn't complete. You have to use some kind of module bundler for this. I'm not front-end developer, but I have heard good opinions on Rollup from my coworkers.

like image 45
Ginden Avatar answered Oct 11 '22 15:10

Ginden