nodejs / corepack

Zero-runtime-dependency package acting as bridge between Node projects and their package managers
MIT License
2.57k stars 169 forks source link

Unhelpful error when using `yarn` when system is unable to resolve package domains via DNS #257

Closed SpencerKaiser closed 1 year ago

SpencerKaiser commented 1 year ago

I recently had an update forced on my router which updated my DNS settings and for whatever reason it failed to resolve the host for the yarnpkg domain and, as a result, this error was thrown:

skaiser [~/Dev/redacted] > yarn --verbose                                                                                                                                      
Internal Error: Error when performing the request
    at ClientRequest.<anonymous> (/opt/homebrew/Cellar/corepack/0.17.2/libexec/lib/node_modules/corepack/dist/corepack.js:43953:14)
    at ClientRequest.emit (node:events:513:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

After like an hour of debugging I thought maybe it could be related to my credentials so I tried yarn login and after logging in all of the issues went away. However, later the issues came back and yarn login was unable to resolve them... I think the first time I was having DNS issues but had yarn installed and the second time I think I was having the same issues but the installer itself couldn't be found.

Any idea what might have caused this? I'm going to try and replicate but wanted to open this issue to help prevent others from going down the same rabbit hole I did.

aduh95 commented 1 year ago

Whether the package was installed from the binary or from homebrew made no difference

I don't understand what you mean by that, what binary, what package? Can you clarify please?

SpencerKaiser commented 1 year ago

I was referring to corepack itself. Whether I installed node + core pack from their site via the installer, via the binary, or via home-brew the result was all the same.

To be honest, I was an idiot and had issues with my DNS but the errors thrown by corepack were still exceptionally unhelpful. If I understand how it works correctly, it seems it's calling out to the individual CLI's (like yarn on demand unless they're already installed, so maybe this issue is better on that repo? Sorry for the mixed wires, I was grasping at straws when I wrote this haha

SpencerKaiser commented 1 year ago

Just updated the details of the issue to better reflect what I found out; happy to move to their repo if you think that's the root cause

aduh95 commented 1 year ago

FYI when you say "installing the package via the binary", it's really unclear, IIUC you meant "installing node+corepack via the installer downloaded on nodejs.org" (because Homebrew also installs a binary, so it's confusing).

DNS issues are not very easy to detect for Corepack, it looks like any other network error, so I'm not quite sure how we could improve the present error message. Maybe you could share how you fixed the issue in case it's beneficial for someone that would encounter the same issue?

SpencerKaiser commented 1 year ago

Sorry for the belated response, I was out of town 😬

IIUC you meant "installing node+corepack via the installer downloaded on nodejs.org"

Sorry about that, yes that's what I meant. I tried multiple variations of installing all the relevant dependencies, specifically where corepack comes from

I'm not quite sure how we could improve the present error message. Maybe you could share how you fixed the issue in case it's beneficial for someone that would encounter the same issue?

I had NO idea that it was an issue with my DNS until I saw a random comment about how it might be a DNS error and suggested trying to curl the relevant site to see if the result was retrievable by your DNS. Once I saw that, I was able to figure out that it was purely a DNS problem and my entire scope of debugging was DNS related (my router).

So maybe a comment with suggestion for debugging? E.g.,

Your connection appears to be offline. If you think this is a mistake, try `curl ...` to see if your DNS settings result in a resolvable host.
aduh95 commented 1 year ago

Your connection appears to be offline.

That's not really right, you would get the same result if the remote server were down, or for other proxy errors. That being said, adding the URL to the error message (or at least the stack trace) would be indeed an improvement. Would you like to contribute a PR?

SpencerKaiser commented 1 year ago

Apologies; that was mostly a bad paraphrasing of the existing error. And sure thing on the contribution; I'll go open a PR now 😄

SpencerKaiser commented 1 year ago

Done 👆