node icon indicating copy to clipboard operation
node copied to clipboard

SyntaxError: Unexpected reserved word when exporting a class in Node v4.0.0

Open JVerstry opened this issue 11 years ago • 5 comments

I have started using Node 4 and implemented a simple class:

"use strict";

class AspectType {

    // ....    

};

export default AspectType;

But I get an error message:

SyntaxError: Unexpected reserved word

I have followed recommendations made in a StackOverflow question: http://stackoverflow.com/questions/32657516/how-to-export-a-es6-class-properly-in-node-4

It looks like a bug to me, or what am I doing wrong? My node version is: v4.0.0.

JVerstry avatar Sep 18 '15 17:09 JVerstry

Yes, you would need to use module.exports = AspectType for now as ES6 modules are not currently implemented

evanlucas avatar Sep 18 '15 17:09 evanlucas

Going to go ahead and close as this isn't directly actionable.

evanlucas avatar Sep 18 '15 18:09 evanlucas

=[ whyyy ??

guisouza avatar Sep 25 '15 07:09 guisouza

where would one use module.exports? I've done a project search and that line comes up around 200 times...

Kamin12 avatar Jan 08 '16 21:01 Kamin12

@kamin12

The object module.exports is what will be returned when someone requires your project.

A short hand for the object is simply exports

The object is created by mode for every file, but you can overwrite it.

Many people do exports.someFunction to export individual functions.

Whatever object module.exports is referring to is what will be returned

MylesBorins avatar Jan 08 '16 22:01 MylesBorins