第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

SyntaxError:意外的令牌功能-異步等待Node.js

SyntaxError:意外的令牌功能-異步等待Node.js

Helenr 2019-10-19 16:21:00
我正在嘗試將Node 6.2.1版與一些代碼一起使用。計(jì)劃將大多數(shù)面向超級(jí)回調(diào)的代碼遷移到看起來(lái)更干凈甚至性能更好的代碼上。我不知道為什么,當(dāng)我嘗試執(zhí)行節(jié)點(diǎn)代碼時(shí),終端拋出錯(cuò)誤。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我想念什么?請(qǐng)給我一些啟示。更新1:我嘗試按照Quentin的建議使用Babel,但是,我仍然收到以下錯(cuò)誤。更新的代碼-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 | })();
查看完整描述

3 回答

?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊

早于7.6版的Node版本不支持異步功能。


如果您使用的是舊版本,則需要將代碼(例如,使用Babel)轉(zhuǎn)換為Node可以理解的JS版本。


就是說(shuō),當(dāng)前(2018年)的Node.js LTS版本是8.x,因此,如果您使用的是較早版本,則應(yīng)強(qiáng)烈考慮升級(jí)。


查看完整回答
反對(duì) 回復(fù) 2019-10-19
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

Node.JS當(dāng)前不完全支持ES6,因此您可以使用asyncawait模塊或使用Bable對(duì)其進(jìn)行轉(zhuǎn)換。


安裝


npm install --save asyncawait

helloz.js


var async = require('asyncawait/async');

var await = require('asyncawait/await');


(async (function testingAsyncAwait() {

    await (console.log("Print me!"));

}))();


查看完整回答
反對(duì) 回復(fù) 2019-10-19
  • 3 回答
  • 0 關(guān)注
  • 603 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)