Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install error 401 when installing a private repository

I am having some issues with NPM and looking for some guidance. When I run the command npm i, I get the following error:

npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://URL-HERE - Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

When I run npm whoami, I see my npm username. When I run npm token, I see a complete list of my tokens (including tokens that should give me permission to install the necessary libraries included in my package.json file. In addition, I have removed any .npmrc files from the repository that I am trying to build.

I have read through this thread from 2018: NPM install resulting in 401 Unauthorized for private repo. However, I have not had any luck with any of the suggestions. Any additional ideas or things that I should investigate?

like image 852
Sam Rothstein Avatar asked Sep 12 '25 02:09

Sam Rothstein


1 Answers

I found either a solution or a workaround. The following resource was particularly helpful for me:

  • https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry

First, generate an access token on your GitHub account. Then, enter the command npm login --scope=@OWNER --registry=https://npm.pkg.github.com. Enter your standard username, your GitHub token as your password, and your email address. Run npm install again, and your modules should be installed. Here is the example from the GitHub guide:

$ npm login --scope=@OWNER --registry=https://npm.pkg.github.com

> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
like image 87
Sam Rothstein Avatar answered Sep 14 '25 19:09

Sam Rothstein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!