ES6 import and export is not supported in Node.js

I am building a project using WebStorm 2016.2.2. I am using version 6.6.0 from Node.js. I installed the JavaScript version for ES6, but I get "unexpected markers" for both import and export . I get no errors for BTW lambda expressions.

Why am I getting this error? Am I doing something wrong or is Node just not supporting import and export without Babel (although I installed the JavaScript version on ES6)?

+5
source share
2 answers

Node.js supports CommonJS modules, however support for ECMAScript modules is currently under development .

At the same time, you will have to use Babel to convert ECMAScript modules to CommonJS. Try using a minimal preset for Node.js, for example babel-preset-node6 .

+6
source

es6 supports import and export, node 6 still does not support import / export of es6, as far as I know.

This question may be useful: NodeJS plans to support es6 import / export modules (es2015)

+3
source

Source: https://habr.com/ru/post/1257812/


All Articles