Yarn: Yarn doesn't read from .npmrc Files for custom registry settings

Created on 11 Oct 2016  路  34Comments  路  Source: yarnpkg/yarn

With an .npmrc file like below:

registry=http://local-npm-install:8080

It seems yarn will not respect this and try the normal NPM upstream.

Most helpful comment

Hey everyone, please use the upvote button on GitHub so we can keep this issue from turning into 1000 comments

All 34 comments

I wonder, so Facebook doesn't have internal registry for private stuff? Or it's just not yet implemented for open source?

Even worse - it uses the yarn registry config when asked to fetch from npm:

 class NpmRegistry extends (_baseRegistry || _load_baseRegistry()).default {
   /* ... */

   request(pathname) {
     // ...
-    const registry = (0, (_misc || _load_misc()).removeSuffix)(String(this.registries.yarn.getOption('registry')), '/');
+    const registry = (0, (_misc || _load_misc()).removeSuffix)(String(this.registries.npm.getOption('registry')), '/');

Hey everyone, please use the upvote button on GitHub so we can keep this issue from turning into 1000 comments

Workaround - put the following into a .yarnrc file in the project root:

registry "https://my-registry.corp"

@jkrems What is the syntax for scoped registries?

@scope:registry "http://place.com"

throws an unknown token error

@tyrsius It's a custom file format (src/lockfile/parse.js). I reverse engineered just enough to make my example above work. ;)

Would be awesome if yarn can address this issue as I work with internal registry daily.

Anyone figured out yet how to configure ca values?

Complete blocker to using this tool. Changed the registry in yarn config (because "drop in replacement for npm"!! 馃), yarn login'd, no dice.

This is a blocker to Airbnb using yarn - just like yarn uses package.json, it should also use every other npm configuration method (.npmrc, as well as all the case-insensitive environment variables npm respects).

I tested putting:

"@mycorp:registry" "https://my-registry.corp"

in my projects yarnrc, it does not appear to work

For registries requiring auth, some work might be needed as well. For example, our .npmrc file looks like this:

registry=https://my-registry.com
_auth=some_auth_token
[email protected]
always-auth=true

Couldn't find a way to make a .yarnrc file that did the same thing.

I have the same issue

If a yarnrc is required for anything, then yarn is not a drop in replacement for npm

I'm trying to use with npm support on Sonatype Nexus 2.11.3-01, I just get this, with a .yarnrc file as first described above:

$ yarn install
yarn install v0.15.1
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find package "express" on the "npm" registry.
info Visit http://yarnpkg.com/en/docs/cli/install for documentation about this command.

If your custom registry requires a trailing slash, yarn is stripping it. rectify this by appending your registry url with a double slash i.e. yarn config set registry http://registry.com/registry/endpoint//

Appears to be related to this line https://github.com/yarnpkg/yarn/blob/0f1db96846badbbe3b43c470c05196eb29437fb4/src/registries/npm-registry.js#L50 but I don't have time to dig any further

@arcticShadow that fixed both issues for me, scoped registry is working now. However, this appears to make the setting global, ignoring the .yarnrc. I would prefer the .yarnrc to control this behavior.

Indeed it does. Couple of options:

  1. echo "registry \"http://registry.com/registry/endpoint//\"" > .yarnrc as mentioned earlier
  2. Theoretically, appending your .npmrc registry URL with a double slash would work for both npm and yarn, although I havn't tested that

I'd like to point out, though, given that the .yarnrc file was already mentioned, and the double slash trick has been mentioned, I thought you would have been able to connect the dots on that one your-self. Perhaps bleeding edge tech is not your thing?

@arcticShadow You misunderstand: putting it in the .yarnrc file does _nothing_. If your global yarn registry is set to npm, and you put a custom registry in .yarnrc, installation will still go to the globally defined registry.

There is no need to be rude.

My apologies - I missed your edit clarifying the behaviour.

Further digging in the registry code shows that the global .yarnrc, the home .yarnrc and the cwd .yarnrc are read (in that order) and stored in an array, where they build out a 'config' object using 'defaults' i.e. only consume a value if it does not already exist. This would appear to merge all the .yarnrc files together in a sane way.

If your local .yarnrc is being ignored, perhaps try checking the syntax? it can be copied out of the ~/.yarnrc which is written by yarn config set... if you wanted to double check.

I tried that, it didn't work. Does it work for you?

You can see here that the cwd has a .yarnrc, but the error shows that it is resolving to the global registry

image

Not sure what to say - Works on my machine (tm)

I've tested this by putting a completely fake URL in my ~/.yarnrc and my real registry in my local.

I've also tested with no registry in ~/.yarnrc

 $ cat ~/.yarnrc
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
registry "http://fakeserver.com//"
$ cat ./.yarnrc
registry "http://artifactory/artifactory/api/npm/orion-virtual-npm//"

I have not tested this with scoped packages though...

Yea, it looks like the scoped package resolution is not working. Perhaps I am just not specifying it correctly.
I've tried these

@scope:registry "http://server.com" #throws token error
scope registry "http://server.com" #throws value error
scope:registry "http://server.com" #does nothing

In my case, I keep .npmrc file side by side with .yarnrc.

.npmrc file:

_auth = xxxxxxx
registry = http://xxx.com
ca = null
email = [email protected]
always-auth = true

路.yarnrc` file:

registry "http://xxx.com"

Keep registry field in both file same and it works.

is that an intentional space preceding your registry? Any reason for that?

@arcticShadow No. It's a typo. I have fixed that.

In my case, I keep .npmrc file side by side with .yarnrc.

This only works for me with Nexus and HTTP basic auth by specifying user and password as part of the URL:

https://user:[email protected]//

Seems like the _auth directive is not picked up from the .npmrc.

@bripkens I think my problem is the same as yours

I tried all kind of setting the custom repo and it keeps failing with ECONNRESET:

yarn install v0.15.1                                                                                                                  
info No lockfile found.                                                                                                               
[1/4] Resolving packages...                                                                                                           
warning mocha > [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade                   
error read ECONNRESET                                                                                                                 
    at exports._errnoException (util.js:1026:11)                                                                                      
    at TCP.onread (net.js:563:26) 

My current .yarnrc is

registry "http://npm.ncgc.local//"

Btw yarn hangs if there's no '\n' in the end.

I can confirm .yarnrc file with registry "https://xxx.com" works.

Now I need to know how to do with .npmrc: strict_ssl=false and auth with token (for using it with sinopia or something like that.

News?

Thank everyone for the comments. I'll have a patch out later today to fix this 馃槃

Created #871 to fix this, pending approval.

Was this page helpful?
0 / 5 - 0 ratings