question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: ctx.onerror is not a function

See original GitHub issue

Environment

  • Nodejs: 8.11.1
  • Koa: 2.5.1
const onerror = err => ctx.onerror(err);
                               ^

TypeError: ctx.onerror is not a function
    at Array.onerror (./server/node_modules/koa/lib/application.js:147:32)
    at listener (./server/node_modules/on-finished/index.js:169:15)
    at onFinish (./server/node_modules/on-finished/index.js:100:5)
    at callback (./dist/server/node_modules/ee-first/index.js:55:10)
    at ServerResponse.onevent (./server/node_modules/ee-first/index.js:93:5)
    at emitNone (events.js:111:20)
    at ServerResponse.emit (events.js:208:7)
    at onFinish (_http_outgoing.js:720:10)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

How to fix it?

  • Replace: const onerror = err => ctx.onerror(err);
  • With: const onerror = ctx.onerror;

paragraph removed by fl0w

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

66reactions
angelbeltrancommented, May 13, 2018

I found out what my problem was.

const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const app = new Koa();

// I forgot to call the bodyParser module...
// app.use(bodyParser);

// better :)
app.use(bodyParser());

@und3fined perhaps this or something like this was your issue?

2reactions
und3finedcommented, May 14, 2018

This is bug with bodyParser(koa-bodyparser) =))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node 8 + Typescript + Koa + koa-Router throws "TypeError
unfortunately, it throws TypeError: ctx.onerror is not a function all the time. Following the examples on GitHub for koa-router ...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
koa ctx.onerror is not a function - 掘金
解决方法问题是在bodyParse 用法上面改成。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Read more >
How to Handle JavaScript Uncaught TypeError: “x” is Not a ...
The Javascript TypeError: "x" is not a function occurs when calling a function on a value or object, which is not actually a...
Read more >
ctx.onerror is not a function"-node.js - appsloveworld
Coding example for the question Node 8 + Typescript + Koa + koa-Router throws "TypeError: ctx.onerror is not a function"-node.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found