我在节点脚本中有以下内容:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
export default Whatever;
I get Unexpected reserved word
关于export
.
我在这里缺少什么?如何在外部文件中指定类定义并包含/需要它?
Node.js 默认不支持 ES6 模块。您需要使用以下命令激活它们--harmony
or --harmony_modules
旗帜。默认是 CommonJS 声明(require/module.exports).
修改您的代码以支持 CommonJS 语法:
"use strict";
class Whatever {
constructor() {
console.log("I'm in the constructor!");
}
}
module.exports = Whatever;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)