导出节点4.x中的ES6类意外保留字 [英] export ES6 class in Node 4.x Unexpected reserved word
本文介绍了导出节点4.x中的ES6类意外保留字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Node脚本中有以下内容:
I have the following in a Node scripts:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
export default Whatever;
我得到意外保留字
关于 export
。
我在这里缺少什么?如何在外部文件中指定类定义并包含/需要它?
What am I missing here? How do you specify a class definition in an external file and include/require it?
推荐答案
Node.js不支持ES6模块默认。您需要使用 - 和谐
或 - harmony_modules
标志来激活它们。默认是CommonJS声明( require
/ module.exports
)。
Node.js doesn't support ES6 modules by default. You would need to activate them with the --harmony
or --harmony_modules
flag. Default ist the CommonJS declaration (require
/module.exports
).
修改代码以支持CommonJS语法:
Modify your code to support the CommonJS syntax:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
module.exports = Whatever;
这篇关于导出节点4.x中的ES6类意外保留字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文