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.
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
inside the project directory which contains
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
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.
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 😊