Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.request TypeError: "listener" argument must be a function #30765

Closed
KalebMills opened this issue Dec 2, 2019 · 5 comments
Closed

http.request TypeError: "listener" argument must be a function #30765

KalebMills opened this issue Dec 2, 2019 · 5 comments

Comments

@KalebMills
Copy link

Error: TypeError: "listener" argument must be a function

Code to reproduce:

let url: string = `http://localhost:${servicePort}/v1/upload?fileName=${OUTPUT_FILE}`
let req = http.request(url, options)
let readStream = fs.createReadStream(ORIGINAL_FILE)
readStream.pipe(req)
readStream.on('error', err => console.log(`READSTREAM: Failed to pipe: ${JSON.stringify(err)}`))
readStream.on('end', () => {
   console.log(`READSTREAM: Completed read.`)
   return;
})

The stack points to let req = http.request(url, options) as the problem line

@KalebMills
Copy link
Author

After switching to use the request library, I have no issue. Seems to be an underlying issue with the http module.

@cjihrig
Copy link
Contributor

cjihrig commented Dec 2, 2019

Can you share the stack, as well as the value of options?

@KalebMills
Copy link
Author

KalebMills commented Dec 2, 2019

Stack:

TypeError: "listener" argument must be a function
      at new ClientRequest (_http_client.js:164:10)
      at Object.request (http.js:38:10)
      at /home/kmills/folder/web-service/test/web-service.ts:161:48
      at new Promise (<anonymous>)
      at Object.<anonymous> (web-service.ts:152:36)
      at step (web-service.js:32:23)
      at Object.next (web-service.js:13:53)
      at /home/kmills/folder/web-service/test/web-service.js:7:71
      at new Promise (<anonymous>)
      at __awaiter (web-service.js:3:12)
      at /home/kmills/folder/web-service/test/web-service.ts:151:48
      at tryCatcher (/home/kmills/folder/web-service/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/home/kmills/folder/web-service/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/home/kmills/folder/web-service/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/home/kmills/folder/web-service/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/home/kmills/folder/web-service/node_modules/bluebird/js/release/promise.js:729:18)
      at _drainQueueStep (/home/kmills/folder/web-service/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/home/kmills/folder/web-service/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/home/kmills/folder/web-service/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/home/kmills/folder/web-service/node_modules/bluebird/js/release/async.js:15:14)

Code snippet with options:

let req = http.request(url, {
   headers: {
      'Transfer-Encoding': 'chunked'
   },
    method: 'POST'
}, () => console.log('Made it to callback'))

@cjihrig
Copy link
Contributor

cjihrig commented Dec 3, 2019

Are you sure you're running version 12.13.1? If so, how did you install it? Is it an official build installed from nodejs.org, nvm, etc.? The reason I ask is because the first stack frame you've provided is:

at new ClientRequest (_http_client.js:164:10)

But, looking at at the code for v12.13.1, that line appears to be:

@KalebMills
Copy link
Author

This is correct, this issue can be closed. Nodemon was calling Node 8, but my current version was v12.13.1. Thanks for your quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants