How to export imported object in ES6?
I often do the following in index.js files that compose several files:
export {default as SomeClass} from './SomeClass';
export {someFunction} from './utils';
export {default as React} from 'react';
This blog entry provides some nice additional examples.
Important note
You should be aware this eslint-rule when accessing these exported imports. Basically, in another file, you shouldn't:
import SomeClassModule from 'SomeClass/index.js';
SomeClassModule.someFunction(); // Oops, error
You should do this:
import SomeClassModule, {someFunction} from 'SomeClass/index.js';
someFunction(); // Ok
You could export imported file with such structure
import First from './First'
import Second from './Second'
/..../
export { First, Second }
For my use case, I explicitly need some sort of explicit import statement so that babel can transpile my es7 code to es5.
The following results in an error You gave us a visitor for the node type "ForAwaitStatement" but it's not a valid type
:
require( 'babel-core/register' ); //transpiles es7 to es5
export {default} from './module_name'
My solution was to explicitly import the module by using require()
:
require( 'babel-core/register' );
export default require( './module_name' ).default;