2

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

1

2 Answers 2

3

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.

take a look at

Sign up to request clarification or add additional context in comments.

2 Comments

I tried switching to node 7.9.0 but I am still getting the same error
Yeah, still exists in 8.3 version.
-1

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).

1 Comment

I tried switching to node 7.9.0 but I am still getting the same error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.