ES6 module compatible export
bradleyayers opened this issue · 5 comments
At the moment chai-enzyme doesn't use an ES6 compatible export for its top level module (build/index.js
). This means that it's impossible to import the library using ES6 without the use of an implicit interop translation layer like webpack.
This poses a problem when compiling statically using something like TypeScript, because
import chaiEnzyme from 'chai-enzyme'
will be compiled to ES5 similar to
var chaiEnzyme = require('chai-enzyme').default;
Currently there is no default export from the library, so this will fail.
Would you be open to exposing an ES6 export rather than a commonjs style?
No. this exposes babel interop to clients, like the .default
Are there known problems with exposing .default
from a commonjs module? I wasn't under the impression that a default
property was specific to Babel, but rather it was the defacto standard for how ES2015 default exports are expressed in ES5.
That being said, .default
isn't the only leakage, there's also the __esModule
property that's leaked. That could be avoided with just
module.exports = …
module.exports.default = module.exports;
Would you be open to that approach?
Another alternative is simply publishing ES2015 under jsnext:main
.
No, there is no standard for ES modules because the module loading spec, and the interop with node, are both not finished yet.
Entry points should only ever use module.exports
- export
syntax is best used only within a project. jsnext:main
is another nonstandard convention that's popped up that imo is harmful to the ecosystem as a whole, and I don't think this project should support it.
I'm with @ljharb on this one, in the beginning of the project we switched from export
to module.exports
btw
Regardless, it's impossible to do modern web dev without browserify or webpack (or similar) - I don't think that's a use case that needs much consideration.