Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29189

Transpile ES2015 gives `export` error

I have a class as follows

export default class Test { 
     constructor() {}
}

Now, I would like to transpile this

$> ./node_modules/.bin/babel-node test.js -o test-es5.js
function (exports, require, module, __filename, __dirname) { export default class Test {
                                                          ^^^^^^

SyntaxError: Unexpected token export
...

.babelrc

{
    "presets": [
         "es2015",
         "stage-0"
    ] 
}

Any suggestions why this is not possible ?

Upvotes: 0

Views: 45

Answers (1)

robertklep
robertklep

Reputation: 203519

You're using the wrong Babel executable.

babel-node is meant as a replacement for the Node interpreter, to run .js files directly. It's not meant to be used as a transpiler.

The -o option for babel-node is interfering with the settings in your .babelrc, causing the error.

Easy fix: use babel instead of babel-node.

Upvotes: 2

Related Questions