How to properly export an ES6 class in Node 4?

If you are using ES6 in Node 4, you cannot use ES6 module syntax without a transpiler, but CommonJS modules (Node’s standard modules) work the same.

module.export.AspectType

should be

module.exports.AspectType

hence the error message “Cannot set property ‘AspectType’ of undefined” because module.export === undefined.

Also, for

var AspectType = class AspectType {
    // ...    
};

can you just write

class AspectType {
    // ...    
}

and get essentially the same behavior.

Leave a Comment