Yarn 3 - How to point installer to correct registry

Viewed 1018

In my current project which uses NPM Enterprise (i.e. has an internal npm registry), I'm following the steps to migrate from Yarn Classic to Modern. Step 7 says to run yarn install. In doing so, the install fails because it's looking for a library in the public registry:

➤ YN0035: │ AppolloReact@npm:^2.3.21: The remote server failed to provide the requested resource
➤ YN0035: │   Response Code: 404 (Not Found)
➤ YN0035: │   Request Method: GET
➤ YN0035: │   Request URL: https://registry.yarnpkg.com/AppolloReact

The Request URL should list our internal registry https://npme.<name>.com. I checked that npm has the correct registry by running

yarn config get registry

As an aside, YN0035 error code is not listed in the Error Codes section, although I guess it means http error.

Anyone have experience with redirecting the installer to point to an internal registry?

3 Answers

For yarn modern, I learned the config param was renamed to npmRegistryServer. So to set/get, the command would be yarn config set|get npmRegistryServer <url>

I'm pretty sure this just doesn't work currently. My investigation led me to this issue thread which was almost helpful.

All the advice in the thread works, assuming you fall into one of two categories:

  1. Your private hosting is used for all dependencies (even if some are just mirroring, in the public case)
  2. You're using a scoped dependency, e.g (@Scope/AppolloReact)

Using the npmScopes field, defining the registry there, will get you halfway. Then you need to yarn login --scope @scope and use your username, and either an API key or password. (I was using artifactory and used an API key tied to my SSO account).

Once that succeeds, a global yarnrc.yml will be created, for me in macOs it was ~/Users/<me>/.yarnrc.yml

This will have the npmAuthToken field, which you can copy the value of and put into your project's yarnrc.yml.

Requiring a scope seems odd, but that seems to be the biggest blocker for me personally, and potentially yourself if i'm reading your question right.

Try removing the lines in the yarn.lock that refer to the particular package and run yarn install. That's what fixed it for me.

My interpretation of what is going on: There seems to be nothing wrong with continuing to refer to a package in a private registry by url in the package.json.

It's rather that yarn install at this point in the migration process is supposed to update the yarn.lock file. But unfortunately something seems to not work in interpreting the old data in the yarn.lock for such a package. Removing these lines in the lock file forces yarn to generate them fresh based on the package.json.

Related