close

How to properly export an ES6 class in Node 4?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How to properly export an ES6 class in Node 4? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How to properly export an ES6 class in Node 4 ?

  1. How to properly export an ES6 class in Node 4 ?

    properly export an ES6 class in Node 4 I had the same problem. What i found was i called my recieving object the same name as the class name. example:
    const AspectType = new AspectType();

  2. properly export an ES6 class in Node 4

    properly export an ES6 class in Node 4 I had the same problem. What i found was i called my recieving object the same name as the class name. example:
    const AspectType = new AspectType();

Method 1

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.

Method 2

I had the same problem. What i found was i called my recieving object the same name as the class name. example:

const AspectType = new AspectType();

this screwed things up that way… hope this helps

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment