SOLVED: Problems with using the "got" http package

I wanted to use the openid-client npm package server-side in my Meteor app but found that it doesn’t work because the http helper package it uses ( misbehaves.

I have traced it down so that just a simple call in a server unit test fails when it tries to connect to localhost:443 instead of the provided host.

  const gotResponse = await got(
  ); // crashes with RequestError: connect ECONNREFUSED

I am fairly sure this is because of its internal promise usage (haven’t tracked it down completely) but I wouldn’t even know where to start fixing it.

Has anyone else successfully used got?

Seems I was chasing down the wrong hole, this was caused by another library patching the https package and breaking it (travis-ci’s agent-base)

This was a quite interesting incompatibility that I thought I’d share a solution to because it seems like something that can happen to many.

Basically, an old version 4.x of agent-base patches the core https package in a way that isn’t compatible with changes introduced in Node 10 and this breaks the got package.

Unfortunately there are a lot of npm packages that bring in that version of agent-base via various xxx-proxy packages and many of them are not yet updated to use newer versions of agent-base.

The owners of got, meanwhile, have refused to add code that detects the incompatibility and alerts the user because “the bug is caused by someone else, just have them update the dependency”.

The solution for me was to use the following code: which is referred to from a github issue comment:

I’m leaving this here in case someone else searches for agent-base or problems using got directly or indirectly.

1 Like

where to put this code inside openid-client?