简体   繁体   English

Node.js不支持ES6导入和导出

[英]ES6 import and export are not supported in Node.js

I'm building a project using WebStorm 2016.2.2. 我正在使用WebStorm 2016.2.2构建一个项目。 I use version 6.6.0 of Node.js. 我使用的是Node.js的6.6.0版本。 I have set the JavaScript version to ES6, but I get "unexpected token" errors for both import and export keywords. 我已将JavaScript版本设置为ES6,但importexport关键字都出现“意外令牌”错误。 I don't get errors for Lambda expressions BTW. 我没有得到Lambda表达式BTW的错误。

Why do I get this error? 为什么我会收到此错误? Am I doing something wrong or Node just does not support import and export without Babel (even though I have set the JavaScript version to ES6)? 我做错了什么或Node不支持importexport没有Babel(即使我已经将JavaScript版本设置为ES6)?

Node.js supports CommonJS modules, however support for ECMAScript modules is currently being designed . Node.js支持CommonJS模块,但目前正在设计对ECMAScript模块的支持。

In the meantime, you'll have to use Babel to transform ECMAScript modules to CommonJS. 在此期间,您将不得不使用Babel将ECMAScript模块转换为CommonJS。 Try using a minimal preset for Node.js builds, like babel-preset-node6 . 尝试使用Node.js构建的最小预设,如babel-preset-node6

es6 does support import and export, node 6 does not support es6 import/export up till now as far as I know. es6确实支持导入和导出,据我所知,节点6到目前为止还不支持es6导入/导出。

This question can be helpful: NodeJS plans to support import/export es6 (es2015) modules 这个问题很有帮助: NodeJS计划支持导入/导出es6(es2015)模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM