This question is related to these. But none of the solutions worked for me.
- Yarn can't find private Github npm registry
- Installing private package from Github Package registry fails with not found/not authorized
I can install a package without issues with npm install @scope/package
however I cannot do the same with yarn: yarn add @scope/package
yarn throws the following error:
An unexpected error occurred: "https://npm.pkg.github.com/download/@scope/package/1.2.8/089b08cffb16074c210ec3a59b04de268ae1c7b3a0492dce110adee3ada05bdd: Request failed \"401 Unauthorized\"".
my .npmrc file looks like this: (tried with and without below .yarnrc)
registry=https://registry.npmjs.org/
//npm.pkg.github.com/:_authToken=MY_AUTHTOKEN
@scope:registry=https://npm.pkg.github.com/
I have tried adding this .yarnrc file:
registry "https://registry.npmjs.org"
"@scope:registry" "https://npm.pkg.github.com"
(without .yarnrc) I've tried this .npmrc file
registry=https://registry.yarnpkg.com/
@scope:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=MY_AUTHTOKEN
always-auth=true
Where MY_AUTHTOKEN
is my Personal Access Token
I've generated from Github. (it has access to everything in packages)
I have tried to:
- remove yarn.lock
- remove .yarnrc
- login with
npm login
using my PAT as the password - logout of npm and removing global .npmrc and .yarnrc
- logging in with
yarn login
In case of any confusion I'm not actually trying @scope and /package but my actual scope and package name.
I do have access to the scope and package on Github.
and again my first setup works just fine with npm. But I cannot get this working with yarn, and cannot find any valid existing solution on SO.
You need only to use .npmrc in the root of your project with this content:
Keep in mind that GITHUB_PERSONAL_TOKEN needs read:packages scope permissions in order to read the packages from your private repo.
The following worked for me in
.npmrc
Using yarn v2, the following worked for me in
.yarnrc.yml
:Firstly, note the lowercase scope name. This is supposed to be the name of the owner of the repository (
MVCE-Superstars
) where the package was published, but the name has to be all lower-cased.The setup
Publishing
.npmrc
OR.yarnrc.yml
file into the repoository.npm login --registry=https://npm.pkg.github.com/
ORyarn npm login --scope=mvce-superstars
commandread:package
,write:package
, andrepo
)npm publish
ORyarn npm publish
Output