Reputation: 10458
I am running node version 6.10.2 I am trying to run this peice of code
import * as events from "events"
class MyClass extends events.EventEmitter {
constructor(x, y){
this.x = x;
this.y = y;
}
compute(){
return this.x * this.y;
}
}
var vow = new MyClass(2,3);
vow.compute();
I am getting this error, How can I make it run?
SyntaxError: Unexpected token import
Upvotes: 2
Views: 4287
Reputation: 4526
Nodejs version 6.. do not support import
and export
. It cover 96% of es6.
So, you have to use babel
to covert your es6 code to es5 version if you like to use Nodejs 6.
Upvotes: 3
Reputation: 866
I'm not sure about it but i think node 6.x doesn't handle import
so you either need a transpiler like babel which will convert your es6 code into es5, you can use require
instead of import or upgrade to node 7.x which should support import
style. (You can use nvm to have many versions of node on your computer).
Upvotes: -1