TypeError: next is not a function
See original GitHub issueI’m trying to log JSON data in an array returned from REST API and getting “TypeError: next is not a function” error. Data is logged in a file but getting that error message. Any suggestion is appreciated.
webService.getData({product_id: 'GOOG'}, (error, response, data) => {
if (error) {
// handle the error
} else {
data.forEach(fill => {
if (typeof fill === 'object') {
logger.info(JSON.stringify(fill));
}
})
}
})
I’m logging data returned from REST API
next();
^
TypeError: next is not a function
at WriteStream.onDrain (C:\Users\nash\wsclient\node_modules\winston\lib\winston\transports\file.js:390:3)
at emitNone (events.js:91:20)
at WriteStream.emit (events.js:185:7)
at onwriteDrain (_stream_writable.js:397:12)
at afterWrite (_stream_writable.js:385:5)
at onwrite (_stream_writable.js:378:7)
at WritableState.onwrite (_stream_writable.js:90:5)
at fs.js:2195:5
at FSReqWrap.wrapper [as oncomplete] (fs.js:2162:5)
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
TypeError: next is not a function - javascript
I'm running a Node.js-server and trying to test this Rest API that I made with Express. It's linked up to MongoDB using Mongoose....
Read more >next is not a function TypeError: next is not a function #3407
Describe the bug After cloning the repo and running docker-compose up, I'm getting the following error message when clicking on log in ...
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 >JavaScript: Uncaught TypeError: n is not a function
This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the...
Read more >Writing middleware for use in Express apps
Calling this function invokes the next middleware function in the app. The next() function is not a part of the Node.js or Express...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have been able to reproduce the issue mentioned by @nengine by feeding in a very large string into the logger.info() call.
After debugging for a while I noticed a possible “this” context issue with the winston file transport.
I noticed that “this._drains” was undefined and becomes NaN after doing the decrement. “this._next” is also undefined which leads to the error mentioned when executing the “next()” call.
The code that sets up the drain event listener will cause the “this” context of the “this._onDrain” to be the newly created “fs.createWriteStream” stored in this._dest property instead of the File transport “this” context.
Changing to:
.on('drain', () => this._onDrain())
in the above code seems to solve the issue. By wrapping in an arrow function the “this” context is preserved. This implies that the “this” context is being set wrong when the “this._onDrain” function is called on a “drain” event.So I believe this is a legitimate bug in the File transport code unless someone thinks otherwise.
Using @next version. Please see below for Winston config. Thanks.