我正在嘗試將Node 6.2.1版與一些代碼一起使用。計劃將大多數面向超級回調的代碼遷移到看起來更干凈甚至性能更好的代碼上。我不知道為什么,當我嘗試執行節點代碼時,終端拋出錯誤。helloz.js(async function testingAsyncAwait() { await console.log("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:3BOZZMOB-M-T0HZ:rest bozzmob$ node -vv6.2.1我想念什么?請給我一些啟示。更新1:我嘗試按照Quentin的建議使用Babel,但是,我仍然收到以下錯誤。更新的代碼-require("babel-core/register");require("babel-polyfill"); (async function testingAsyncAwait() { await console.log("Print me!"); })();日志BOZZMOB-M-T0HZ:rest bozzmob$ babel helloz.js > helloz.trans.jsSyntaxError: helloz.js: Unexpected token (3:7) 1 | require("babel-polyfill"); 2 | > 3 | (async function testingAsyncAwait() { | ^ 4 | await console.log("Print me!"); 5 | })();
SyntaxError:意外的令牌功能-異步等待Node.js
Helenr
2019-10-19 16:21:00