ES6 Modules default exports interop with CommonJS · Issue #2719 · microsoft/TypeScript (original) (raw)
CommonJS cannot requires a package transpiled from TypeScript ES6 Modules using default export well.
TS 1.5-alpha transpiles default exports:
// foo.ts export default foo;
to:
// foo.js ("main" in this package.json) exports.default = foo;
So users of this package foo
need to add .default
property to require()
.
var foo = require('foo').default;
It's a little messy...
Babel resolves this issue.
http://babeljs.io/docs/usage/modules/#interop
Interop
In order to encourage the use of CommonJS and ES6 modules, when exporting a default
export with no other exportsmodule.exports
will be set in addition toexports["default"]
.exports["default"] = test; module.exports = exports["default"];
If you don't want this behaviour then you can use the
commonStrict
module formatter.
It sounds pretty nice and actually works for me.