How I was able to fix the error `Request failed \"401 Unauthorized` while installing packages using yarn

How I was able to fix the error `Request failed \"401 Unauthorized` while installing packages using yarn

ยท

2 min read

Here is a step by step guide on how I was able to resolve the error

Request failed \"401 Unauthorized` while installing packages using yarn

I keep getting the error after I cloned a repository from Github and I wanted to install all the packages using the command below.

yarn install

After searching for solutions online. I realized that the project was using Github packages for login and I was supposed to login with the command below.

npm login --registry=https://npm.pkg.github.com

I dug more for solutions and noticed the

.npmrc file

inside the project directory which contains

@zanzee:registry=https://npm.pkg.github.com

Before I was able to successfully log in using

npm login --registry=npm.pkg.github.com

I setup a Github Personal Access Token and enabled the option of

read:packages

in my Github personal access token as shown in the image. To set up your personal access token, follow the guide provided here.

After adding the personal access token, I had to log in using npm login --registry=npm.pkg.github.com command with my username and personal access token but got another error while running the command yarn install again.

WhatsApp Image 2021-09-05 at 7.27.25 PM.jpeg

I resolved the error by looking inside the directory indicated in the error message and deleted the folder inside the tmp because yarn is reusing the cache directory, but git doesn't like overwriting one branch with another in that directory.

After resolving the two errors, I ran yarn install again and it successfully installed all the packages in the repository.

Thank you for reading till the end. I hope you found it useful ๐Ÿ˜Š