Questions tagged [es6-modules]

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

2668 questions
79
votes
4 answers

Wildcard or asterisk (*) vs named or selective import es6 javascript

Just wondering which one is the best way to use import: import * as Foo from './foo'; VS: import { bar, bar2, bar3 } from './foo'; In terms of efficiency, say for example, I'm using webpack for bundling all the JavaScript files. Will the first one…
andiwin
  • 1,552
  • 3
  • 14
  • 27
78
votes
12 answers

Error [ERR_REQUIRE_ESM]: How to use es6 modules in node 12?

From https://2ality.com/2019/04/nodejs-esm-impl.html Node 12 should support es6 modules; however, I just keep getting the error: Question: How do I make a MVP of using es6 modules in node 12? package.json { "name": "dynamic-es6-mod", "version":…
Armeen Moon
  • 18,061
  • 35
  • 120
  • 233
78
votes
9 answers

How to use ES6 modules from dev tools console

As far as I understand it, if I create an ES6 module, I can only import it from code that is itself a module. This means non-module code, i.e. inline Javascript, or the Chrome dev tools console can never access code that is in a module. Is that…
Timmmm
  • 88,195
  • 71
  • 364
  • 509
77
votes
5 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       foo.js will be stored in the browser cache. This is desirable until I push a new…
spinners
  • 2,449
  • 3
  • 23
  • 34