I am trying to run some ES6 code in my project but I am getting an unexpected token export error.
export class MyClass {
constructor() {
console.log("es6");
}
}
You are using ES6 Module syntax.
This means your environment (e.g. node.js) must support ES6 Module syntax.
NodeJS uses CommonJS Module syntax (module.exports
) not ES6 module syntax (export
keyword).
Solution:
babel
npm package to transpile your ES6 to a commonjs
targetor
Examples of CommonJS syntax are (from flaviocopes.com/commonjs/):
exports.uppercase = str => str.toUpperCase()
exports.a = 1