koa ctx.onerror is not a function

430 阅读1分钟
/Users/mun/node/fast/node_modules/koa/lib/application.js:165
const onerror = err => ctx.onerror(err);
                               ^

TypeError: ctx.onerror is not a function
    at onerror (/Users/mun/node/fast/node_modules/koa/lib/application.js:165:32)
    at AsyncResource.runInAsyncScope (node:async_hooks:199:9)
    at listener (/Users/mun/node/fast/node_modules/on-finished/index.js:170:15)
    at onFinish (/Users/mun/node/fast/node_modules/on-finished/index.js:101:5)
    at callback (/Users/mun/node/fast/node_modules/ee-first/index.js:55:10)
    at ServerResponse.onevent (/Users/mun/node/fast/node_modules/ee-first/index.js:93:5)

解决方法

问题是在 bodyParse 用法上面

    app
        .use(bodyParse);

改成

    app
        .use(bodyParse())