Installing private package from Github Package registry fails with not found/not authorized

I found the solution which unfortunately is not well documented anywhere but a mix of different resources - and it's quite simple.

No matter whether you use npm or yarn, just have the following .npmrc in place (yarn will also include this):

registry=https://registry.yarnpkg.com/

@GITHUB_USERNAME:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=AUTH_TOKEN
always-auth=true

Some comments:

  • always-auth is needed, at least when using yarn (haven't tested using npm)
  • Adding the above in the .yarnrc instead doesn't work. Somehow yarn has issues when authentication is needed.
  • Now you can easily install your private packages with yarn add @GITHUB_USERNAME/PACKAGE_NAME or the npm equivalent.
  • Include registry=https://registry.yarnpkg.com/ for yarn or registry=https://registry.npmjs.org/ for npm

I hope this solution works also in your case. Otherwise let me know what issues you face and I'm happy to share some of the research on this topic and where the solution may hide.