ES6 import and export are not supported in Node.js

后端 未结 2 1098
孤街浪徒
孤街浪徒 2021-01-18 15:55

I\'m building a project using WebStorm 2016.2.2. I use version 6.6.0 of Node.js. I have set the JavaScript version to ES6, but I get \"unexpected token\" errors for both

相关标签:
2条回答
  • 2021-01-18 16:36

    Node.js supports CommonJS modules, however support for ECMAScript modules is currently being designed.

    In the meantime, you'll have to use Babel to transform ECMAScript modules to CommonJS. Try using a minimal preset for Node.js builds, like babel-preset-node6.

    0 讨论(0)
  • 2021-01-18 16:41

    es6 does support import and export, node 6 does not support es6 import/export up till now as far as I know.

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

    0 讨论(0)
提交回复
热议问题