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.

`nock` does not support the new Node.js 10.9 signature `http.request(url[, options][, callback])`

See original GitHub issue

What is the expected behavior? Using the new signature for http.request(url, options[, callback])/http.get(url, options[, callback]) (introduced in Node.js v10.9, should work with nock.

What is the actual behavior? With nock (by merely requireing nock), it throws:

events.js:288
    throw new errors.ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function. Received type object
    at ClientRequest.once (events.js:288:11)
    at new ClientRequest (_http_client.js:150:10)
    at Object.request (http.js:41:10)
    at ...\node_modules\nock\lib\intercept.js:405:16
    at Object.module.request (...\node_modules\nock\lib\common.js:140:14)
    at requestWithUrlAndOptions (...\script.js:27:5)
    at Object.<anonymous> (...\script.js:42:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)

Possible solution I haven’t looked at the code, but I suspect nock assumes the second argument is always the callback and uses it as such, whereas in Node.js 10.9+, the second argument can be an object (with the third being the callback). It should be trivial to detect that situation and pass the correct arguments to http.request() (or something like that 😁).

How to reproduce the issue

Runkit: Example link

Does the bug have a test case? (Not sure wht this means.)

Versions

Software Version(s)
Nock All (at least up to 10.0.0)
Node 10.9+

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
nijynotcommented, Feb 2, 2019

@gr2m I’ll join in on the fun 😃, just submitted a PR (https://github.com/nock/nock/pull/1428) that fixes this bug. Would be cool if someone could review it.

0reactions
nockbotcommented, Aug 13, 2019

🎉 This issue has been resolved in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP | Node.js v19.3.0 Documentation
maxHeaderSize; http.request(options[, callback]); http.request(url[, ... It parses a message into headers and body but it does not parse the actual headers ...
Read more >
How is an HTTP POST request made in node.js?
My program doesn't actually send the http request post when I keep the function handling errors. Once I deleted it, it worked. Your...
Read more >
nock: Versions - Openbase
(Added in v11.3); Add support for the http.request signatures added in Node 10.9; Scopes can be filtered using the system environment or any...
Read more >
nock - Devpost
Nock is an HTTP mocking and expectations library for Node.js ... or if host is not part of it, Nock will automatically add...
Read more >
Embed a CLA Signing Page Using NodeJS with the HelloSign ...
Get your CLAs signed easier using the Dropbox Sign API and GitHub API. ... is not the case, go to Nodejs.org and get...
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