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 add for scoped package against private registry with creds for public npm fails #2554

Open
seansfkelley opened this issue Jan 25, 2017 · 3 comments

Comments

@seansfkelley
Copy link

seansfkelley commented Jan 25, 2017

The title is a bit of a mouthful. In more words: when .npmrc (or, presumably, .yarnrc) are configured with both a private registry URL and an auth token for publishing to public npm, installing scoped packages breaks. The private registry in question here is Artifactory, and the going theory is that Yarn is sending the creds (inappropriately: the config is for two different URLs), which Artifactory is not happy about, and 401s (since the creds are for public npm, not Artifactory). I'm not sure why scoped packages would be treated differently, as it works fine otherwise.

Following is some commands to illustrate:

> pwd
~

> cat .yarnrc
cat: .yarnrc: No such file or directory

> cat .npmrc
registry=<private registry URL that works fine with npm and non-scoped packages>
//registry.npmjs.org/:_authToken=<my auth token>

> yarn add @types/d3-scale --verbose
yarn add v0.19.1
info No lockfile found.
verbose Performing "GET" request to "https://yarnpkg.com/latest-version".
[1/4] 🔍  Resolving packages...
verbose Performing "GET" request to "<correct private registry URL ...>/@types%2fd3-scale".
verbose Request "<correct private registry URL ...>/@types%2fd3-scale" finished with status code 401.
verbose Error: Couldn't find package "@types/d3-scale" on the "npm" registry.
    at MessageError (/usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/lib/errors.js:8:5)
    at /usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/lib/resolvers/registries/npm-resolver.js:207:15
    at next (native)
    at step (/usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
    at /usr/local/Cellar/yarn/0.19.1/libexec/lib/node_modules/yarn/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
    at process._tickCallback (internal/process/next_tick.js:103:7)
error Couldn't find package "@types/d3-scale" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

> npm install @types/d3-scale
~
└─┬ @types/d3-scale@1.0.6 
  └── @types/d3-time@1.0.5 

> yarn add d3-scale          
yarn add v0.19.1
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
├─ d3-array@1.0.2
├─ d3-collection@1.0.2
├─ d3-color@1.0.2
├─ d3-format@1.0.2
├─ d3-interpolate@1.1.3
├─ d3-scale@1.0.4
├─ d3-time-format@2.0.3
└─ d3-time@1.0.4
✨  Done in 2.45s.

# edit .npmrc...

> cat .npmrc 
registry=<same registry URL>

> yarn add @types/d3-scale 
yarn add v0.19.1
warning No license field
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
├─ @types/d3-scale@1.0.6
└─ @types/d3-time@1.0.5
warning No license field
✨  Done in 1.50s.
@bluekeyes
Copy link

For additional background, the Artifactory instance is configured to allow anonymous access. If you provide no credentials, you can read whatever you like. If you provide any credentials, Artifactory attempts to validate them and returns the 401 status (in this case, because the user does not exist.)

@AndyMoreland
Copy link

AndyMoreland commented Jan 31, 2017

I think this is the offending line of code: https://github.com/yarnpkg/yarn/blob/master/src/registries/npm-registry.js#L56 (the last clause).

Reading in context it seems like the author assumes that "scoped" implies "authenticated".

@KubaZ
Copy link

KubaZ commented Feb 20, 2017

Had exact same issue last friday, had to remove auth token from ~/.npmrc to be able to download scoped package from local artifactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants