Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM Registry: What If I Cannot Reach It? #160

Open
AllanChain opened this issue Feb 1, 2021 · 0 comments
Open

NPM Registry: What If I Cannot Reach It? #160

AllanChain opened this issue Feb 1, 2021 · 0 comments
Labels
blog: programming @post This is a blog post tag: javascript |178272204-7e20ff98-56d1-457d-842f-70a4ecd17e0f.png tag: network

Comments

@AllanChain
Copy link
Owner

View Post on Blog

The story of mirrors, ipv6, and yarn 2

npm-reg


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.

@AllanChain AllanChain added the tag: javascript |178272204-7e20ff98-56d1-457d-842f-70a4ecd17e0f.png label Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog: programming @post This is a blog post tag: javascript |178272204-7e20ff98-56d1-457d-842f-70a4ecd17e0f.png tag: network
Projects
None yet
Development

No branches or pull requests

1 participant