Bug: The "listener" argument must be of type Function. Received type object
See original GitHub issueWhat is the expected behavior? It should work!
What is the actual behavior? It crashes
Possible solution no idea, yet
How to reproduce the issue/test case
const http = require('http');
const https = require('https');
const nock = require('nock');
nock('https://httpbin.org').persist()
.post('/post').reply(200, (uri, reqBody) => {
return {
"hits": {
"total": 0
}
}
});
const fetch = (url, o) => new Promise((resolve, reject) => {
let body = o && o.body;
if (typeof body === 'object') {
o.headers = { ...o.headers, 'content-type': o.headers && o.headers['content-type'] || 'application/json' };
body = JSON.stringify(body);
}
const req = (/^https:/.test(o && o.protocol || url) ? https : http).request(url, o);
req.once('error', reject);
req.once('response', res => {
const bufs = [];
res.on('data', buf => bufs.push(buf));
res.on('end', () => {
const text = Buffer.concat(bufs);
if (res.headers.location) return fetch(res.headers.location, o || url).then(resolve)
resolve(/^application\/json/.test(res.headers['content-type']) ? JSON.parse(text) : text);
});
res.on('error', reject);
});
if (body && typeof body.pipe === 'function') return body.pipe(req);
if (body) {
req.write(body);
}
req.end();
});
(async () => {
await fetch('https://httpbin.org/post', { method: 'POST', body: { wat: 1 } }).then(console.log, console.error);
})()
Versions
Software | Version(s) |
---|---|
Nock | 10.0.0 |
Node | 10.11.0 |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:8 (4 by maintainers)
Top Results From Across the Web
The "listener" argument must be of type Function - Stack ...
The reason here is syntax error, you are closing bracket before passing the callback method. Solution: bot.on("message", function(message) { ...
Read more >"listener argument must be of type function" error with v6.2.2+
I'm receiving an error when upgrading to version 6.2.2 of the launchdarkly-node-server-sdk library. Error Message: The \"listener\" argument ...
Read more >The "listener" argument must be of type function. Received ...
So im making a discord bot and i am getting this error if running TypeError [ERR_INVALID_ARG_TYPE]: The “listener” argument must be of type ......
Read more >The “listener” argument must be of type Function. Something ...
I cannot replicate the error. If I take the code from your question, add the two require calls, and run it, I don't...
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 Free
Top 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
I’m fairly certain this is due to the change in node’s http api with version 10 (which is LTS as of today, btw).
compare http 8.x with http 10.x
I won’t be able to look into it myself, if you could give it a try that’d be great. Or maybe someone else can help out. It’s hacktoberfest, plenty of folks looking to contribute right now 😃