首頁  >  問答  >  主體

koa2 - node.js koa ctx=> 報錯

剛開始接觸koa 一直提示ctx=> 這個>報錯無法運行實在弄不清了也找不到資料求大神幫忙
這是報錯
app.use(ctx => {

         ^

SyntaxError: Unexpected token >

#
at exports.runInThisContext (vm.js:69:16)
at Module._compile (module.js:432:25)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
at startup (node.js:124:16)
at node.js:803:3

這是原始碼
const Koa = require('koa');
const app = new Koa();

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

app.listen(3000);

console.log('app started at port 3000....');

阿神阿神2688 天前617

全部回覆(2)我來回復

  • 習慣沉默

    習慣沉默2017-05-16 13:35:32

    記得koajs2應該是

    app.use(async (ctx, next) => { await next(); });

    另外檢查一下nodejs的版本是不是太低了

    回覆
    0
  • 天蓬老师

    天蓬老师2017-05-16 13:35:32

    找到原因了 果然node.js 版本太低了 謝謝一樓

    回覆
    0
  • 取消回覆