This question already has an answer here:
- Pass options to ES6 module imports 6 answers
Previously:
var debug = require('debug')('http')
, http = require('http')
, name = 'My App';
With es6, how can I import and invoke right away like the first line?
import debug from 'debug'();
is a no no?
You'll need two lines:
The import syntax is a declarative import syntax, it does not execute any functions.
Correct. Keep in mind that the
import
statement is analogous to more than a simplerequire()
statement -- it also creates a binding of the "loaded" module to a local variable.That is,
...is more close in behavior/semantics to
...than it is to simply
Analogies to commonjs-style module loaders will obviously break down at some point, but at the end of the day it's a "no no" due to the plain and simple fact that
import debug from 'debug'
doesn't actually resolve to anything that you can invoke (or otherwise reference).