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

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

Closed
raybooysen opened this issue Oct 11, 2016 · 34 comments · Fixed by #839
Closed

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

raybooysen opened this issue Oct 11, 2016 · 34 comments · Fixed by #839

Comments

@raybooysen
Copy link

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.

@sebmck sebmck added the cat-bug label Oct 11, 2016
@nkabardin
Copy link

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

@jkrems
Copy link
Contributor

jkrems commented Oct 11, 2016

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')), '/');

@jamiebuilds
Copy link
Contributor

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

@jkrems
Copy link
Contributor

jkrems commented Oct 11, 2016

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

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

@kyeotic
Copy link

kyeotic commented Oct 11, 2016

@jkrems What is the syntax for scoped registries?

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

throws an unknown token error

@jkrems
Copy link
Contributor

jkrems commented Oct 11, 2016

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

@andypham
Copy link

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

@alexgorbatchev
Copy link

Anyone figured out yet how to configure ca values?

@tomccabe
Copy link

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

@ljharb
Copy link

ljharb commented Oct 11, 2016

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).

@bbatha
Copy link

bbatha commented Oct 11, 2016

I tested putting:

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

in my projects yarnrc, it does not appear to work

@devongovett
Copy link
Contributor

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=test@example.com
always-auth=true

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

@benmonro
Copy link

I have the same issue

@ljharb
Copy link

ljharb commented Oct 11, 2016

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

@majgis
Copy link

majgis commented Oct 11, 2016

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.

LeSuisse added a commit to Enalean/docker-tuleap-test-karma that referenced this issue Oct 11, 2016
We can not replace bower (at least not without some hacks) until the
issue [1] is solved.
Also note, that as of today private registries requiring authentication
can not be used [2] [3].

[1] yarnpkg/yarn#617 (comment)
[2] yarnpkg/yarn#606
[3] yarnpkg/yarn#547
@arcticShadow
Copy link

arcticShadow commented Oct 11, 2016

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

const registry = removeSuffix(String(this.registries.yarn.getOption('registry')), '/');
but I don't have time to dig any further

@kyeotic
Copy link

kyeotic commented Oct 11, 2016

@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.

@arcticShadow
Copy link

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?

@kyeotic
Copy link

kyeotic commented Oct 11, 2016

@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.

@arcticShadow
Copy link

My apologies - I missed your edit clarifying the behaviour.

@arcticShadow
Copy link

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.

@kyeotic
Copy link

kyeotic commented Oct 11, 2016

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

@kyeotic
Copy link

kyeotic commented Oct 11, 2016

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

image

@arcticShadow
Copy link

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...

@kyeotic
Copy link

kyeotic commented Oct 12, 2016

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

@mocheng
Copy link

mocheng commented Oct 12, 2016

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

.npmrc file:

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

·.yarnrc` file:

registry "http://xxx.com"

Keep registry field in both file same and it works.

@arcticShadow
Copy link

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

@mocheng
Copy link

mocheng commented Oct 12, 2016

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

@bripkens
Copy link
Contributor

bripkens commented Oct 12, 2016

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:password@myrepo.example.com//

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

@matheusrocha89
Copy link

@bripkens I think my problem is the same as yours

@OlegZee
Copy link

OlegZee commented Oct 12, 2016

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 > jade@0.26.3: 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.

@ghost
Copy link

ghost commented Oct 12, 2016

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?

@yarnpkg yarnpkg locked and limited conversation to collaborators Oct 12, 2016
@sebmck
Copy link
Contributor

sebmck commented Oct 12, 2016

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

@sebmck
Copy link
Contributor

sebmck commented Oct 12, 2016

Created #871 to fix this, pending approval.

@sebmck sebmck closed this as completed Oct 12, 2016
@sebmck sebmck removed the cat-bug label Oct 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.