17koa / koa-generator-examples

一起学koa
http://17koa.com/koa-generator-examples/
MIT License
480 stars 76 forks source link

用babel-node运行官方例子报错 #36

Open yreenchan opened 8 years ago

yreenchan commented 8 years ago
const Koa = require('koa');
const app = new Koa();

// logger

app.use(async (ctx, next) => {
  const start = new Date;
  await next();
  const ms = new Date - start;
  console.log(`${ctx.method} ${ctx.url} - ${ms}`);
});

// response

app.use(ctx => {
  ctx.body = 'Hello World';
});

app.listen(3000);

如上代码,用babel-node运行时,报下面错误

C:\Users\YreenChan\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel
-core\lib\transformation\file\index.js:548
      throw err;
      ^

SyntaxError: E:/xampp/htdocs/www/nodejs/koajs2/test.js: Unexpected token (6:26)
  4 | // logger
  5 |
> 6 | app.use(async (ctx,[22
m next) => {
    |                           ^
  7 |   const start = new Date;
  8 |   await next();
  9 |   const ms = new Date - start;[
22m
    at Parser.pp.raise (C:\Users\YreenChan\AppData\Roaming\npm\node_modules\babe
l-cli\node_modules\babylon\index.js:1413:13)
    at Parser.pp.unexpected (C:\Users\YreenChan\AppData\Roaming\npm\node_modules
\babel-cli\node_modules\babylon\index.js:2895:8)
    at Parser.pp.parseAsyncArrowFromCallExpression (C:\Users\YreenChan\AppData\R
oaming\npm\node_modules\babel-cli\node_modules\babylon\index.js:593:47)
    at Parser.pp.parseSubscripts (C:\Users\YreenChan\AppData\Roaming\npm\node_mo
dules\babel-cli\node_modules\babylon\index.js:544:21)
    at Parser.pp.parseExprSubscripts (C:\Users\YreenChan\AppData\Roaming\npm\nod
e_modules\babel-cli\node_modules\babylon\index.js:511:15)
    at Parser.pp.parseMaybeUnary (C:\Users\YreenChan\AppData\Roaming\npm\node_mo
dules\babel-cli\node_modules\babylon\index.js:481:19)
    at Parser.pp.parseExprOps (C:\Users\YreenChan\AppData\Roaming\npm\node_modul
es\babel-cli\node_modules\babylon\index.js:412:19)
    at Parser.pp.parseMaybeConditional (C:\Users\YreenChan\AppData\Roaming\npm\n
ode_modules\babel-cli\node_modules\babylon\index.js:394:19)
    at Parser.pp.parseMaybeAssign (C:\Users\YreenChan\AppData\Roaming\npm\node_m
odules\babel-cli\node_modules\babylon\index.js:357:19)
    at Parser.pp.parseExprListItem (C:\Users\YreenChan\AppData\Roaming\npm\node_
modules\babel-cli\node_modules\babylon\index.js:1224:16)