Heim > Fragen und Antworten > Hauptteil
node版本是v6.2.2
新建一个app.js
内容如下
async function responseTime(ctx, next) {
const start = new Date();
await next();
const ms = new Date() - start;
ctx.set('X-Response-Time', `${ms}ms`);
}
然后node app.js
报如下错误:
mbp:hybrid-statistic wfp$ node app.js
/Users/wfp/Work/hybrid-statistic/app.js:28
async function responseTime(ctx, next) {
^^^^^^^^
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 Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
怎么破?
PHPz2017-04-17 15:10:33
Node会在Chrome 55 Stable发布后正式支持async/await,不过最新的V7版本在打开--harmony的模式的时候可以支持.