-
Notifications
You must be signed in to change notification settings - Fork 84
__dep__['default'] is incompatible with existing AMD/CJS scripts #69
Comments
Those are not named exports. Those are properties of the default export.
I agree, but this is a feature of the ES6 module system, and the transpiler should emulate it faithfully instead of inventing new semantics that mesh better with ES5 module systems. |
Requiring a full ES6 codebase is not going to happen for a very, very long time. Allowing compatibility with existing module formats (which is the whole point of this, right?) will help get ES6 modules ubiquitous. Maybe a |
there's a I'll expose it on the command line, though :) |
I don't think such a project should be called es6-module-transpiler. It will cause users to write code that does not work in ES6 environments (which will be in Firefox, Chrome, and Node within the next few months), despite having ES6 syntax. In other words, ES6 modules will not become ubiquitous, but instead some variant of them that uses the same syntax but is not ES6-compatible and does not deserve the name. Instead, meshing with existing module systems should be done in the same way it will be done in the ES6 timeframe: via wrapper modules and modified loaders. You should be lobbying RequireJS to change its loader behavior to account for the special |
This is future-hostile, as is the very existence of that flag. |
Another avenue besides getting changes made to your favorite loaders is to work on tools that will automatically generate wrapper modules. Again, such tools will be necessary in the ES6 timeframe as well, so this path seems much more sensible to me than creating yet-another-module-format. |
thought: |
See #66, it should not transpile that way as it creates yet another future-hostile pattern. |
good points @domenic. @thomasboyt maybe the flag should be removed? It ought to be the job of requirejs and node, etc, to adapt to this for greater future compatibility. |
My guess is loaders won't want to do this, which is understandable. However, by not supporting a stop gap in the loaders we are pushing yet another build step onto library authors, which is going to be an uphill battle already. |
What if the transpiler outputs this instead? // amd
define(['foo'], function(__dependency1__) {
var foo = 'default' in __dependency1__ ? __dependency1__['default'] : __dependency1__;
// code
});
// cjs
var __dependency1__ = require('foo');
var foo = 'default' in __dependency1__ ? __dependency1__['default'] : __dependency1__; This way anything authored in ES6 uses 'default' so its not future hostile, and "legacy" amd/cjs scripts will continue to just work™. |
The problem with that is it will allow import fs from "fs"; whereas in ES6 that will not work, because |
@domenic -- this problem just bit me recently and will prevent me when rewriting my AMD modules as ES6 modules. I don't care to break my dependencies and tell them that the "fix" is to rewrite all their requires as Is there a place I can read up on the reasoning behind why everything has to be a named export? Why can't we just export a frozen object and call that "named exports"? You said "it is a feature of the ES6 module system" to have both default and named exports. How about we make it not a feature of the ES6 module system? It causes such a severe compatibility issue with basically all the existing module systems. Feeling a lot like @rpflorence right now. |
ES6 modules are not meant to be designed to be compatible with AMD or CommonJS consumers. That was not a design goal of the new system. From: Evan Winslowmailto:[email protected] @domenichttps://github.com/domenic -- this problem just bit me recently and will prevent me when rewriting my AMD modules as ES6 modules. I don't care to break my dependencies and tell them that the "fix" is to rewrite all their requires as var Foo = require('Foo').default, or else they have to rewrite them in ES6, or wrapper modules, or whatever. Is there a place I can read up on the reasoning behind why everything has to be a named export? Why can't we just export a frozen object and call that "named exports"? You said "it is a feature of the ES6 module system" to have both default and named exports. How about we make it not a feature of the ES6 module system? It causes such a severe compatibility issue with basically all the existing module systems. Feeling a lot like @rpflorencehttps://github.com/rpflorence right now. — |
http://wiki.ecmascript.org/doku.php?id=harmony:modules seems to imply it What is the design goal that is driving this incompatibility? I assume I On Thu, Jul 31, 2014, 10:18 AM Domenic Denicola [email protected] ES6 modules are not meant to be designed to be compatible with AMD or From: Evan Winslowmailto:[email protected] @domenichttps://github.com/domenic -- this problem just bit me recently Is there a place I can read up on the reasoning behind why everything has You said "it is a feature of the ES6 module system" to have both default Feeling a lot like @rpflorence<https https://github.com/rpflorence:// — — |
README.md says:
Yes they do:
I don't get this. It makes working with existing libraries that support one module format or the other unnecessarily complex.
Just take whatever the default export is, and then add the named exports onto it as properties.
The text was updated successfully, but these errors were encountered: