When I see the compiled code by Babel, they do not seem to be equivalent.
Actually, the former transforms to exports.A = A
, which is not equivalent to mod
babel6 is not supported export default A
to modules.export=A
you should add a plugin
You can use the following in Node v6:
"use strict"
class ClassName {
// class code
}
module.exports = ClassName
Save the above file as ClassName.js
To import it in another file Test.js:
"use strict"
var ClassName= require('./ClassName.js');
var obj = new ClassName( Vars . . . );
For more Info:
Here's an article on exporting classes from modules in Node v6
You can use
export default class A {
}
Or
class A {
}
export default A;
Which will export as
exports["default"] = A;
module.exports = exports["default"];
There's an explanation why in the interop section here.
In order to encourage the use of CommonJS and ES6 modules, when exporting a default export with no other exports
module.exports
will be set in addition toexports["default"]
.