Lukasz S
Lukasz S

Reputation: 668

401 Unauthorized: [Package name] error during npm install from azure DevOps feed

I'm using AzureDevop artifacts for npm feeds. When I try to do npm install I'm getting 401 Unauthorized exception.

Any idea what is causing it ?

Upvotes: 3

Views: 9730

Answers (4)

Marcel
Marcel

Reputation: 780

It might be worth pointing out that even if your token is clearly NOT expired, still try to renew it and see what happens. This solved my problem (yarn install with 401 Unauthorized)

Upvotes: 0

Bizhan
Bizhan

Reputation: 17125

Most probably your token is expired.

  1. Go to Azure Devops
  2. From this menu enter image description here at the top right corner choose Personal access tokens
  3. Find the expired token which matches your problem e.g. has Packaging (Read) access to the failing url in 401 error message.
  4. Select the token and Regenerate.
  5. go back to your console and run vsts-npm-auth -config .npmrc -F

If it's your first time you have to create a new token with sufficent access to packaging and run npm install -g vsts-npm-auth in your console before running vsts-npm-auth -config .npmrc -F (I always put that -F there even if it's not needed).


If you're still having problem I suggest you find the detailed instructions in the Azure Devops:

  1. Go to Artifacts
  2. Connect to feed
  3. npm
  4. click on Having issues? See the instructions for using a Personal Access Token to authenticate. and read the whole instructions.

Upvotes: 1

Mwiza
Mwiza

Reputation: 9011

Your authorization token has probably expired. Go to you .npmrc file and look for the following section to confirm expiration date of token, as highlighted: enter image description here

To update it, Login to azure DevOps:

  1. Click on Artifacts
  2. Select connect to feed enter image description here
  3. Select npm
  4. Under project setup select other then enter image description here
  5. Click on generate npm credentials
  6. Copy the credentials
  7. Paste replace the expired token in .npmrc file

Upvotes: 4

Lukasz S
Lukasz S

Reputation: 668

I figured it out. My authorization token expired. Just needed to go to feed/connect-to-feed and regenerate token for npm and put it into .npmrc file.

Upvotes: 3

Related Questions