Sam Rothstein
Sam Rothstein

Reputation: 870

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?

Upvotes: 4

Views: 15094

Answers (1)

Sam Rothstein
Sam Rothstein

Reputation: 870

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

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

Upvotes: 8

Related Questions