Difference between import X and import * as X in node.js (ES6 / Babel)?

import * as lib from 'lib';

is asking for an object with all of the named exports of ‘lib’.


export var config = _config;
export var db = _db;
export var storage = _storage;

are named exports, which is why you end up with an object like you did.


import lib from 'lib';

is asking for the default export of lib.


e.g.

export default 4;

would make lib === 4. It does not fetch the named exports. To get an object from the default export, you’d have to explicitly do

export default {
  config: _config,
  db: _db,
  storage: _storage
};

Leave a Comment