Home  >  Q&A  >  body text

koa2 - node.js koa ctx=> error report

I just started to contact koa and it keeps prompting ctx=> This> error cannot be run. I can’t figure it out and can’t find the information. Please help me.
This is an error.
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

This is the source code
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 days ago620

reply all(2)I'll reply

  • 習慣沉默

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

    Rememberkoajs2should be

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

    Also check if the nodejs version is too low

    reply
    0
  • 天蓬老师

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

    I found the reason. Sure enough, the node.js version is too low. Thank you, first floor

    reply
    0
  • Cancelreply