pgsandstrom / package-json-upgrade

MIT License
49 stars 10 forks source link

Usage of local host registries fails after upgrade of `npm-registry-fetch` to 16.1.0 #49

Closed ymeine closed 11 months ago

ymeine commented 1 year ago

EDIT: I added a comment below, correcting some of my statements. Most of what's written here remains relevant, but a few parts are wrong: the issue is not HTTP vs HTTPS, but rather local host vs remote registries. Updating the whole description would be tedious, so I'm leaving it mostly as is, and just updated a few parts.


Hello,

When you fixed the issue #48 I posted, I checked the new version and it worked as expected. But that was only with regards to what the issue was actually about. I hadn’t noticed some changes had broken something else (I discovered this with some delay only because I had a forced break in the middle of my task - hardware problems, brrr).

Context and investigation

So, my whole goal is to run a local, private npm registry, and for that I use Verdaccio. I run the latter on address http://127.0.0.1:4873. What actually matters here is the use of a registry with the HTTP protocol, instead of HTTPSlocal host registry instead of a remote one.

It looks like the package npm-registry-fetch made quite some changes in that area. Here’s what I found out:

Differences I can see when upgrading:

Possible solutions

I fully understand that the source of the issue is unlikely to be on your side, but the fact is you are using a package version which leads to that issue. Either the latter has a bug, or there’s a more complex combination of events leading to this issue (some wrong usage/configuration somewhere).

That means there are several options (not exclusive):

The detailed investigation above may not be necessary here, especially if you just choose to downgrade the dependency, but it may be useful for two things:


Thanks again in advance for your time, and trust me, I know how hard it is to dedicate time to project development, maintenance, etc.

That’s why I don’t want to overwhelm you too much with crazy investigations, and I’m not asking or expecting you to push it further to see if this is a bug or not. If I personally had more resources these days, I would probably push it myself and bother one of the 3rd parties instead. But right now it looks too complex to me to know who’s the culprit here.

ymeine commented 1 year ago

So, in the meantime I thought I would be saved by switching to HTTPS, even though it requires much more setup, harder to automate. Turns out I was wrong: the culprit is not HTTP vs HTTPS, it's rather local host vs the rest. And 127.0.0.1 is a local host.

Now, my initial investigation still points out most of the relevant facts: versions upgrades, 3rd party packages involved, failing piece of code, etc. But the interpretation is slightly different.

What's for sure: the issue is completely related to the behavior of custom Agent implementations. Now, what's weird is what I experimented in debug mode:

After checking a bit more, I realized that forcing isLocalhost to false at that time actually picked a different agent implementation (as I expected), and it turns out to be the Node.js' builtin HTTP agent (_http_agent).

That means multiple things:


As a conclusion, it's even more complex that I imagined. The downside is that I can't use HTTPS as a workaround, since the problem is rather than it's a local host, and that I cannot change it.

pgsandstrom commented 1 year ago

Thank you for the bug report. That is very interesting. Could you clone this repo, downgrade npm-registry-fetch to 14, and confirm that everything works? I would be willing to downgrade if it fixes your issue.

ymeine commented 1 year ago

I already tried it. It should have been the first thing I did, but I instead I went debugging right away, to clarify the issue.

At some point, I tested with the version you previously set, 14.0.5, and it worked. Since I have a use case set up on my side, let me try latest 14.x and even 15.x while I'm at it, so then you can pick the one you judge more relevant.

ymeine commented 1 year ago

Now, would 15.0.0 bring other issues, since it's a major version change, I don't know. 14.0.5 could be a safer choice, but the decision is up to you (considering you also updated other packages anyways and it seems fine).

pgsandstrom commented 11 months ago

I downgraded npm-registry-fetch to 14.0.5. Let me know if you run into any other problems.

ymeine commented 11 months ago

I just checked now, it all works fine! Thanks for the quick update