我正在尝试使用节点版本6.2.1与我的一些代码.已经计划将大多数超级回调代码迁移到看起来更干净,可能性能更好的内容.
我不知道为什么,当我尝试执行节点代码时,终端会抛出一个错误.
helloz.js
- (async function testingAsyncAwait() {
- await console.log("For Trump's Sake Print me!");
- })();
日志 –
- BOZZMOB-M-T0HZ:rest bozzmob$node helloz.js
- /Users/bozzmob/Documents/work/nextgennms/rest/helloz.js:1
- (function (exports,require,module,__filename,__dirname) { (async function testingAsyncAwait() {
- ^^^^^^^^
- SyntaxError: Unexpected token function
- at Object.exports.runInThisContext (vm.js:53:16)
- at Module._compile (module.js:513:28)
- at Object.Module._extensions..js (module.js:550:10)
- at Module.load (module.js:458:32)
- at tryModuleLoad (module.js:417:12)
- at Function.Module._load (module.js:409:3)
- at Function.Module.runMain (module.js:575:10)
- at startup (node.js:160:18)
- at node.js:456:3
- BOZZMOB-M-T0HZ:rest bozzmob$node -v
- v6.2.1
我失踪了什么请给我一些灯光.
更新1:
我尝试使用Babel作为Quentin建议,但是,我仍然收到以下错误.
更新代码
要求(“巴别核/注册”);
要求( “巴别-填充工具”);
- (async function testingAsyncAwait() {
- await console.log("For Trump's Sake Print me!");
- })();
日志 –
- BOZZMOB-M-T0HZ:rest bozzmob$babel helloz.js > helloz.trans.js
- SyntaxError: helloz.js: Unexpected token (3:7)
- 1 | require("babel-polyfill");
- 2 |
- > 3 | (async function testingAsyncAwait() {
- | ^
- 4 | await console.log("For Trump's Sake Print me!");
- 5 | })();