NPM Registry: What If I Cannot Reach It? #160
Labels
blog: programming
@post
This is a blog post
tag: javascript
|178272204-7e20ff98-56d1-457d-842f-70a4ecd17e0f.png
tag: network
View Post on Blog
Above image background from https://travelandleisureindia.in/great-wall-of-china-visitors-cap/
Well, you might say,
npm config set registry xxx
does the trick. I know how to set npm registry mirror of course. I just have another story to tell.Registries are Shown in Lock File
Npm or yarn classic, no matter which you are using, recommends you to commit the lock file (at least in several situations) and writes registry into lock file. What if you want to speed up development using one registry while speeding up CI with another registry, due to differrent network environments? What if the registry committed in version control is simply not reachable by others, which cannot be easily solved without deleting lock file? For more situations, see yarnpkg/yarn/issues/3330.
Say Hello to Yarn 2
Although PnP mode introducedn in yarn 2 has many capability issues, you can simply turn it of by setting
nodeLinker: node-modules
in.yarnrc.yml
. Enjoy registry agnostic lock file... to some degree.https://registry.npm.taobao.org
is not the case, because it doesn't follow the standard url patterns from the npm registry. See yarnpkg/berry#2192 (comment) for the explanation. But good news,https://repo.huaweicloud.com/repository/npm/
works great.Why Registry Works Fine in Browser but Fails in Terminal?
This is a little bit confusing. I pinged
registry.npmjs.org
and found it was an ipv6 address. Then I tried to ping resolved ipv4 address (dig registry.npmjs.org A
) but all of them are timed out. Maybe both npm and yarn do not support ipv6, in year 2021?Nico Schottelius' blog post The Nodejs in IPv6 only networks problem is to the point. It's basically a NodeJS bug (nodejs/node/pull/31567). NodeJS reorders the DNS result so that IPv4 addresses come before IPv6 addresses by default, making it unfriendly to ipv6 network environments.
Workaround
Set hosts to an ipv6 address to overwrite DNS result.
The text was updated successfully, but these errors were encountered: