Questions tagged [es6-modules]

The standard module system for JavaScript, introduced in ECMAScript 6 (2015).

1761 questions
80
votes
4 answers

ES2015 "import" not working in node v6.0.0 with with --harmony_modules option

I am using node v6.0.0 and wanted to use ES2016 (ES6). However I realized that the "import" syntax is not working. Isn't "import" fundamental to for writing modular code in ES2015? I tried running node with --harmony_modules option as well but still…
joy
  • 3,499
  • 6
  • 35
  • 72
75
votes
7 answers

Using import fs from 'fs'

I want to use import fs from 'fs' in JavaScript. Here is a sample: import fs from 'fs' var output = fs.readFileSync('someData.txt') console.log(output) The error I get when I run my file using node main.js is: (function (exports, require, module,…
birdybird03
  • 1,343
  • 2
  • 14
  • 33
67
votes
3 answers

ES6 module Import giving "Uncaught SyntaxError: Unexpected identifier"

For a personal project, I'm trying to use ES6 import to write cleaner code. As first test, I'm writing an object that should generate a menu. The whole code is working when I'm directly loading up the class, yet when using the import and export in…
ZeroThe2nd
  • 1,572
  • 1
  • 10
  • 14
66
votes
2 answers

Destructuring a default export object

Can I destructure a default export object on import? Given the following export syntax (export default) const foo = ... function bar() { ... } export default { foo, bar }; is the following import syntax valid JS? import { foo, bar } from…
sfletche
  • 36,606
  • 25
  • 86
  • 108
62
votes
2 answers

ES6 Destructuring and Module imports

I was under the impression that this syntax: import Router from 'react-router'; var {Link} = Router; has the same final result as this: import {Link} from 'react-router'; Can someone explain what the difference is? (I originally thought it was a…
Guy
  • 59,547
  • 93
  • 241
  • 306
61
votes
4 answers

Output an ES module using webpack

With Rollup I can output an ES module by simply setting the format option to 'es'. How can I do the same with webpack? If it's not possible now, does webpack have any plans to add it? The only thing I've found in the documentation for…
Michał Perłakowski
  • 70,955
  • 24
  • 137
  • 155
59
votes
3 answers

Inlining ECMAScript Modules in HTML

I've been experimenting with new native ECMAScript module support that has recently been added to browsers. It's pleasant to finally be able import scripts directly and cleanly from JavaScript.      /example.html