【发布时间】:2016-07-12 13:48:53
【问题描述】:
我已经在 windows 上安装了官方 node js 版本 v5.9.1 (x64),并尝试使用 ECMAScript 对类进行一些工作。我写了一个简单的类来测试:
"use strict";
export class httpWrapper {
getPage(options){
// some code
}
};
我把这个类放在httpWrapper.js 中。如您所见,我在此处使用 export 来导出课程。然后我用这段代码创建了'main.js':
'use strict';
import httpWrapper from 'httpWrapper';
let theInstance = new httpWrapper();
当我运行node main.js 时出现错误:
import httpWrapper from 'httpWrapper';
^^^^^^
SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:142:18)
at node.js:939:3
我还尝试使用 node 运行 httpWrapper.js,我得到了:
export class httpWrapper {
^^^^^^
SyntaxError: Unexpected token export
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:142:18)
at node.js:939:3
node js 中是否提供导入/导出功能?因为这些语句不起作用,我不能使用导出/导入,你想如何导出/导入类?
【问题讨论】:
-
不,暂时没有
标签: javascript node.js syntax ecmascript-6 ecmascript-5