yarnrc file ignored when trying to add private package

Created on 4 Oct 2019  Â·  6Comments  Â·  Source: yarnpkg/yarn

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

What is the current behavior?
Yarn tries to install a package from npm when the package is not on there (it is on Github). Instructions on yarnrc are ignored. Installing the same package using npm (and npmrc) works as expected.

If the current behavior is a bug, please provide the steps to reproduce.
Yarn steps that don't work
.yarnrc

registry "https://registry.npmjs.org"
"@hemalr:registry" "https://npm.pkg.github.com/hemalr"

Command: yarn add @hemalr/react-blocks

Error - error Couldn't find package "@hemalr/react-blocks" on the "npm" registry.

Equivalent steps on npm that works:

.npmrc

registry=https://registry.npmjs.org
@hemalr:registry=https://npm.pkg.github.com/hemalr

Command - npm install @hemalr/[email protected]

What is the expected behavior?
Yarn should install the package from the registry specified in .yarnrc

Please mention your node.js, yarn and operating system version.
OS - 10.14.6 - MacOS Mojave
Node - 12.11.0
Yarn - 1.19.0

Any guidance, or pointers to obvious things I am missing are very much appreciated. I've been trying to install a package for 8 hours now! 😆 (I'm secretly crying).

Thanks in advance!

Most helpful comment

So I found a workaround in my case,

I had a personal access token in the .npmrc for authentication to github packages, which I had to double it this way:

//npm.pkg.github.com/:_authToken=<TOKEN_VALUE>
//npm.pkg.github.com/<OWNER>/:_authToken=<TOKEN_VALUE>

Without the second line which matched the value for my scoped registry I would get the "couldn't find in the npm registry" error. Without the first one (the original one) I get a 401

Hope this helps

All 6 comments

I have the same exact issue with 1.19 and a registry on github packages

@HemalR are you also in the context of a create-react-app or react-native application?

No in my case it’s a vanilla Gatsby application (new and unaltered from the
Gatsby starter template).

On Fri, 4 Oct 2019 at 7:07 pm, Patrick Lussan notifications@github.com
wrote:

@HemalR https://github.com/HemalR are you also in the context of a
create-react-app application?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/yarnpkg/yarn/issues/7597?email_source=notifications&email_token=ADXI67ZUJXTJIUJ62QK5XRDQM4PVVA5CNFSM4I5KK2I2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEALJ53A#issuecomment-538353388,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADXI67Z2QBQL3DFDYHUBBWLQM4PVVANCNFSM4I5KK2IQ
.

So I found a workaround in my case,

I had a personal access token in the .npmrc for authentication to github packages, which I had to double it this way:

//npm.pkg.github.com/:_authToken=<TOKEN_VALUE>
//npm.pkg.github.com/<OWNER>/:_authToken=<TOKEN_VALUE>

Without the second line which matched the value for my scoped registry I would get the "couldn't find in the npm registry" error. Without the first one (the original one) I get a 401

Hope this helps

@plus-

Thanks for that, I'll test it out! (For now, for this new project I have already switched to NPM). I guess if your workaround is doing the trick, then the issue is that yarn is not outputting the correct error message (where it is an authentication error rather than looking in the wrong registry).

For reference, npm authenticates by looking at the system root .npmrc file which has the Github token to grant the system access to the repo in question.

Unfortunately, @plus- solution didn't work to me. But, found a very similar solutions which worked to me posted in this issue: https://github.com/yarnpkg/yarn/issues/7552#issuecomment-538376858

Still a bit _hacky_ IMO but works to me 🤓

Was this page helpful?
0 / 5 - 0 ratings