module exports

Domenic Denicola domenic at
Fri Mar 14 07:51:34 PDT 2014

Indeed. If you have used Node.js extensively, I am sure you are familiar with this paradigm.

From: es-discuss <es-discuss-bounces at> on behalf of Mark Volkmann <r.mark.volkmann at>
Sent: Friday, March 14, 2014 10:50
To: Rick Waldron
Cc: es-discuss at
Subject: Re: module exports

Is the common use case for "export default" when you want to give users of the module an easy way to obtain a single function?

So instead of users doing this:

import {someFn} from 'wherever';

they can do this:

import someFn from 'wherever';

On Fri, Mar 14, 2014 at 9:40 AM, Rick Waldron <waldron.rick at<mailto:waldron.rick at>> wrote:

On Fri, Mar 14, 2014 at 10:07 AM, Mark Volkmann <r.mark.volkmann at<mailto:r.mark.volkmann at>> wrote:
On Fri, Mar 14, 2014 at 8:54 AM, Kevin Smith <zenparsing at<mailto:zenparsing at>> wrote:

I'm trying to understand how that compares to ES6 modules. I see how in ES6 I can import specific things from a module or I can import everything a module exports.

You can't really import all exported bindings.  You can import the module instance object itself:

    module M from "wherever";

which will give you access to all of the exports.

That's what I meant by importing all the exports.
I'd prefer it if the syntax for that was

import M from "wherever";

As Kevin said, this already means "import the default export from 'wherever'"

That way I could think of import is doing something like destructuring where the other syntax below is just getting some of the exports.

import {foo, bar} from "wherever"';

Am I correct that a "default" export can be somewhere in the middle ... a subset of everything that is exported?

Not really.  The default export is literally just an export named "default".  There is sugar on the import side, where you can leave off the braces:

    import foo from "somewhere";

is equivalent to:

    import { default as foo } from "somewhere";

The specialized default export syntax is just plain confusing and should be jettisoned, in my opinion.  It would be less confusing for users to simply write:

    export { foo as default };

I fail to see why sugar over this form is necessary.

Because it doesn't allow for the Assignment Expression form (specifically, function expressions) that developers expect to be able to write:

  export default function() {}


R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list