Yarn: Running a yarn command with yarn sets registry to https://registry.yarnpkg.com

Created on 23 May 2018  路  10Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
When yarn is used to run a yarn command, the registry used is 'https://registry.yarnpkg.com'.
When npm is used to run a yarn command, the registry used is the one defined in the npm config (npm config get registry).

If the current behavior is a bug, please provide the steps to reproduce.
Confirmed by adding a test script to my package.json:
"dump-config": "yarn config list"

$ yarn dump-config -->

info npm config
{ registry: 'https://registry.yarnpkg.com', ...

$ npm run dump-config -->

info npm config
{ registry: 'https://my.private.registry/', ...

Note: I am using a private registry and have not confirmed this is also true with the public npm registry.

Also, I think I first started seeing this behavior after bumping from [email protected] to [email protected], but I haven't isolated that yet.

What is the expected behavior?
The registry should be the one defined in npm config, whether running the yarn script with npm or with yarn.

Please mention your node.js, yarn and operating system version.
Node 8.11.2
Yarn 1.6.0
OSX High Sierra 10.13.14

triaged

Most helpful comment

Workaround: add --registry "https://my.private.registry/" to .yarnrc

All 10 comments

Workaround: add --registry "https://my.private.registry/" to .yarnrc

Nice, the -- before registry solved a different issue for me: I use both npm and yarn on my machine and for npm a private registry is set. Despite having a .yarnrc file both in the user directory and in the project directory, yarn was always using the registry set for npm but I want to use the public registry for yarn. So I used yarn config set registry https://registry.yarnpkg.com and yarn config get registry displayed the registry set in yarn config correctly, but was not using it on yarn install/add. Only --registry 'https://registry.yarnpkg.com' seems to override the registry from npm, yarn config list shows it to be even set in the npm config (which is not true). Sadly, I could not found anything about this override in the docs.

In addition to your expected behavior, I would expect:

  • yarn uses the registry set in npm but only when there is no one set in the yarn config
  • the yarn registry does not have to be set with --
  • yarn config get registry gets the one actually used for yarn install/add

Bump?

This is causing repeated, hard-to-debug issues for us with Lerna and Jenkins. We keep running into problems caused by the fact that we have to use npm on Jenkins to work around this issue, while we yarn locally, resulting in slightly different dependencies installed across the two environments. Lerna comes into play because it, by nature, invokes scripts within packages from a master script (e.g. Custom boot script invoked via yarn boot runs lerna boostrap, which then runs yarn scripts within each package in our monorepo).

What's the difference between registry "my.registry.org" and --registry "my.registry.org"?

This one also pops up intermittently for me, and --registry "https://registry.npmjs.com" >> .yarnrc in the same folder as the monorepo's package.json finally got yarn to resolve my private package from npm.

This one also pops up intermittently for me, and --registry "https://registry.npmjs.com" >> .yarnrc in the same folder as the monorepo's package.json finally got yarn to resolve my private package from npm.

doing that sorted my jenkins build

We have just encountered this issue. Our scenario:

  • We have a monorepo with several modules, each with their own build.
  • A master build file runs the sub-builds in the repo.
  • We have a .npmrc file with a custom registry at the root of the repo.

The issue seems to be that when running a yarn command (in our case install), environment variables are being set including registry = https://registry.yarnpkg.com. Based on npm config priorities this environment variable takes precedent over the project level settings.

This causes the sub-builds to fail as they attempt to fetch packages from the official yarn registry rather than the private registry.

As above, adding a .yarnrc file with the private registry is a workaround.

environment variables are being set including registry = https://registry.yarnpkg.com

I just ran into this too. https://circleci.com/gh/intuit/auto/8683

The tool we build (auto) was being ran like yarn auto shipit. shipit runs npm deprecate and npm was picking up the registry set by yarn.

I understand why you set the registry when installing dependencies (or doing any other interactions with a registry). But I don't see why you would ever want to have the registry overridden when running anything through yarn run or yarn SCRIPT_NAME. I can really only seeing it lead to weird, hard to debug behavior.

@arcanis (or any other team member): Is this behavior that could be changed? It seems simple to not override the registry when using yarn run and I would be happy to submit a pull request.

Sooo...I just came across this again, trying to add a convenience script that yarn adds things but found that when invoked via an npm script, the registry is different than just a naked yarn add call from my bash prompt. Stumbled around google for a bit and lo and behold, here I am again! Hello, future self.

Any way this can be addressed by Yarn team? (@torifat ?) Currently on [email protected].

Any way this can be addressed by Yarn team? (@torifat ?) Currently on [email protected].

You are five minors late, and one major too 馃檪

Was this page helpful?
0 / 5 - 0 ratings