How can I use the default import alias in Javascript?

Using ES6 modules, I know I can use named imports

import { foo as bar } from 'my-module'; 

And I know that I can import default imports

 import defaultMember from 'my-module'; 

I would like to have a default import alias, and I thought the following would work

 import defaultMember as alias from 'my-module'; 

but this leads to a parsing error.

How can I (or can?) Import an alias by default?

+283
javascript ecmascript-6 es6-modules
Sep 01 '16 at 23:24
source share
1 answer

defaultMember already an alias - it should not be the name of the exported function / thing. Just do

 import alias from 'my-module'; 

Alternatively you can do

 import {default as alias} from 'my-module'; 

but it is rather esoteric.

+544
Sep 01 '16 at 23:30
source share



All Articles