![](/img/trans.png)
[英]node.js / ES6 / class creation : SyntaxError: Unexpected reserved word
[英]export ES6 class in Node 4.x Unexpected reserved word
我在Node腳本中有以下內容:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
export default Whatever;
我得到了關於export
Unexpected reserved word
。
我在這里錯過了什么? 如何在外部文件中指定類定義並包含/要求它?
Node.js默認不支持ES6模塊。 您需要使用--harmony
或--harmony_modules
標志激活它們。 默認是CommonJS聲明( require
/ module.exports
) 。
修改代碼以支持CommonJS語法:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
module.exports = Whatever;
ES6模塊在Node中不穩定,但您可以使用--harmony_modules
來啟用它們。 顯然不建議在生產環境中使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.