Why can't I import a default export with "import ... as" with BabelJS

Ecmascript 6Babeljs

Ecmascript 6 Problem Overview


In version 5.6.4 of BabelJS, I seemingly cannot "import ... as." Here are examples of what I am trying to do:

In file 'test.js':

export default class Test {};

In file 'test2.js' (in the same directory):

import Test as Test2 from './test';

I have also tried to do:

import {Test as Test2} from './test';

Even though it says nothing about that here: http://babeljs.io/docs/learn-es2015/#modules

And only uses brackets in the non-default syntax here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

Has anyone done this successfully?

EDIT: It is absolutely because of the default keyword. So, in this case, the question becomes, does anyone have any links to documentation that states that I should not be able to alias a default import? ECMA or Babel.

Ecmascript 6 Solutions


Solution 1 - Ecmascript 6

You can import the default export by either

import Test2 from './test';

or

import {default as Test2} from './test';

The default export doesn't have Test as a name that you would need to alias - you just need to import the default under the name that you want.

The best docs I've found so far is the article ECMAScript 6 modules: the final syntax in Axel Rauschmayers blog.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBTCView Question on Stackoverflow
Solution 1 - Ecmascript 6BergiView Answer on Stackoverflow