hapijs / hapijs/wreck

err: TypeError: Client request error: Cannot read private member #context from an object whose class did not declare it

Open
#305 17 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
376
Forks
110
PR merge metrics
No merged PRs in 30d

Description

### Runtime

NodeJS

### Runtime version

v20

### Module version

18.0.1

### Last module version without issue

_No response_

### Used with

simple-oauth2

### Any other relevant information

Can not work out if this is a wreck issue or a nodejs issue. Or perhaps even a simple-oauth2 problem.

### What are you trying to achieve or the steps to reproduce?

Using simple-oauth2 to get a token and that modules uses @hapi/wreck

simple-oauth2 does nothing more than this:
this.#client = Wreck.defaults(httpOptions);
const response = await this.#client.post(url, options);
where url is a string.

It feels like something wreck is doing is triggering the NodeJS internal url library to try do something weird although I can't see how an external library like wreck could be doing anything so bad as to cause such an issue. I am pretty certain this is a NodeJS issue but something special is happening here because it's unfathomable that v20.10 has come along and nobody usin

### What was the result you got?

err: TypeError: Client request error: Cannot read private member #context from an object whose class did not declare it

I added a `console.log(new Error().stack))` to on Error and got this - not particularly informative:
Error
at ClientRequest.onError (/opt/APP/node_modules/@hapi/wreck/lib/index.js:192:13)
at Object.onceWrapper (node:events:629:26)
at ClientRequest.emit (node:events:514:28)
at _destroy (node:_http_client:875:13)
at onSocketNT (node:_http_client:895:5)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
2023-11-20T09:41:01+11:00 [ERROR] - Failed to Get Token - err: TypeError: Client request error: Cannot read private member #context from an object whose class did not declare it

The actual error is thrown in `lib/internal/url.js` which is new to NodeJS v20. I've raised https://github.com/nodejs/node/issues/50891 against NodeJs to try get at this from both directions but it's strange we've got to v20.10 and nobody else is experiencing this. It happens in v20.0 (which is when url.js got introduced).

### What result did you expect?

No error :-)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.