nodejs框架——koa2踩坑

一 ctx.onerror is not a function

TypeError: ctx.onerror is not a function
    at onerror (/Users/xiexingjie/Developer/mcn/demo/server/node_modules/koa/lib/application.js:179:32)
    at AsyncResource.runInAsyncScope (async_hooks.js:197:9)
    at listener (/Users/xiexingjie/Developer/mcn/demo/server/node_modules/on-finished/index.js:170:15)
    at onFinish (/Users/xiexingjie/Developer/mcn/demo/server/node_modules/on-finished/index.js:101:5)
    at callback (/Users/xiexingjie/Developer/mcn/demo/server/node_modules/ee-first/index.js:55:10)
    at ServerResponse.onevent (/Users/xiexingjie/Developer/mcn/demo/server/node_modules/ee-first/index.js:93:5)
    at ServerResponse.emit (events.js:412:35)
    at ServerResponse.emit (domain.js:475:12)
    at onFinish (_http_outgoing.js:792:10)
    at callback (internal/streams/writable.js:513:21)
[ERROR] 10:08:53 TypeError: ctx.onerror is not a function

原因: 使用koa-bodyparser錯誤,koa-bodyparser是個方法

const bodyParser = require("koa-bodyparser");
//錯誤
app.use(bodyParser); 
// 正確
app.use(bodyParser());
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • koa2框架筆記 Node.js是一一個異步的世界,官方API支持的都是callback 形式的異步編程模型,這會...
    wanminglei閱讀 683評論 0 0
  • 框架提出的背景 ES6/7帶來的變革 自ES6確定和ES7中async/await開始普及,Node的發(fā)展變得更加...
    宮若石閱讀 8,705評論 1 14
  • koa2框架筆記 Node.js是一一個異步的世界,官方API支持的都是callback 形式的異步編程模型,這會...
    wanminglei閱讀 1,957評論 0 2
  • 1. 認識Koa Koa 是基于Node平臺的下一代web開發(fā)框架 1.1 簡介 koa 是由 Express 原...
    時光如劍閱讀 1,110評論 0 4
  • 前言 本文僅為koa2上傳文件(圖片/文本/視頻/音頻)到七牛云的記敘。 關于我是如何找到該文檔的? 在沒有具體...
    liwuwuzhi閱讀 2,134評論 0 0

友情鏈接更多精彩內(nèi)容