0

I am using Nodejs v9.0.0. I have to use Babel for transpiling the code into ES5 because if not transpiled it throws error unexpected token import. So If anyone know how to use the real ES6 version in nodejs and which nodejs version. Please let me know.

Thanks

3
  • Install Node v10.9.0. v9 does not support ES6 module syntax. Commented Aug 16, 2018 at 4:32
  • If you want to resolve unexpected token import issue refer to this link Commented Aug 16, 2018 at 4:33
  • I am using a SDK which requires Nodejs 9.0 not above that. Is it possible to use ES6 with Node v9.0.0? Commented Aug 16, 2018 at 4:47

1 Answer 1

2

All es6 is supported by NodeJS since 8.10 version : look at the column NodeJS in the es6 compatibility array. Unforfunately the ES6 Module syntax is not supported or only with the flag experimental.

So you need to convert your ESModule in CJSModule. You can do it with the babel-plugin-transform-es2015-modules-commonjs plugin

In your .babelrc file :

"plugins": [
    "transform-es2015-modules-commonjs"
]

If you use babel-register the transformation occurs when the file is required(imported)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.