Do Anonymous Exports Solve the Backwards Compatibility Problem?

David Herman dherman at
Wed Dec 19 14:29:42 PST 2012

On Dec 18, 2012, at 12:56 PM, Kevin Smith <khs4473 at> wrote:

> At first glance, it seems like anonymous exports might provide a way for pre-ES6 (read: Node) modules and ES6 modules to coexist.

That's not what anonymous exports are for. They're there to support the use case of modules that want to support a popular idiom, a style.

> There are two directions that an interop strategy will have to deal with.  First, we might want an ES6 module to be loaded by a pre-ES6 module:
>     // "es5-module.js"
>     var ES6Module = require("es6-module.js");
> We might want to use this when a dependency is upgraded to ES6 modules and we want to leave the dependent alone.  Now, since ES6 modules are asynchronous, and require is synchronous, we must load "es6-module.js" *before* "es5-module.js" is executed.  The only way to do that is to statically analyze "es5-module.js", searching for calls to require.

It's much easier than that. It's Node. Module loading is synchronous. Node can simply provide a synchronous module loading form. That's not going to be standardized in ES6, but there's nothing inconsistent about providing it. (Remember: JavaScript does not *idiomatically* use synchronous I/O, but it does not *disallow* synchronous I/O.)

If you want to use Node modules in the browser, well, you'll have to get more clever, but I don't think we need to solve this problem in ES6.

> What about the other direction?  Let's say that we want to load an ES5 module from an ES6 module:

Loader hooks are the answer here.


More information about the es-discuss mailing list