Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM ERR Code E401: Unable to authenticate, need: Bearer authorization

I downloaded a NodeJS application from GitHub and facing the following error when executing npm install.

npm ERR! code E401 npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/c1156c2f-a3bb-4fc4-ac07-3eab96da8d10, Basic realm="https://pkgsprodeus21.pkgs.visualstudio.com/", TFS-Federated 

My Node version is 6.13.1 and NPM version is 6.13.4. Following is the content of package.json file:

{   "name": "DemoApp",   "version": "1.0.0",   "description": "A social oasis for lovers of pizza.",   "repository": "****",   "main": "index.js",   "scripts": {     "start": "node index.js"   },   "author": "****",   "license": "MIT",   "dependencies": {     "@hapi/boom": "7.4.2",     "@hapi/catbox": "10.2.1",     "@hapi/catbox-redis": "5.0.2",     "@hapi/cookie": "10.1.0",     "@hapi/good": "8.2.0",     "@hapi/good-squeeze": "5.2.0",     "@hapi/hapi": "18.3.1",     "@hapi/inert": "5.2.1",     "@hapi/joi": "15.1.0",     "@hapi/vision": "5.5.2",     "aws-sdk": "2.488.0",     "bcryptjs": "2.4.3",     "bootflat": "2.0.4",     "fs-extra": "8.1.0",     "handlebars": "4.1.2",     "lodash": "4.17.13",     "pg": "7.11.0",     "sequelize": "5.9.4"   } } 

I have been stuck at this issue since yesterday and still no luck finding the solution. Any help would be highly appreciated.

like image 906
Gaurav Ahuja Avatar asked Jan 24 '20 10:01

Gaurav Ahuja


People also ask

How do I resolve npm err code e401?

Try Deleting the package-lock. json file before running the command "npm install" after upgrading the node versions, if you have not done that. If that will not work try removing the . npmrc file in $HOME directory as mentioned in this post.

How do I update npm package manager?

Method 1: Using npm update command to update the node package manager. Method 2: Using npm@latest command to update the node package manager. Method 3: Using PPA repository (only for Linux). Method 4: Using cache cleaning & stable installing (only for Linux).

How do I find npm registry URL?

You can show the registry of a specific package with the npm view command. When you use npm config get registry you will see the default registry.

Why do we need .npmrc file?

The npmrc manages the npm config files. The config setting for npm is gotten from the command line, environment variables and the npmrc files. You can use the npm config command to update and edit the contents of the user and global npmrc files.


2 Answers

This is what worked for me.

First, delete the .npmrc file in your Users folder. This folder:

C:\Users\[your user name] 

Then run this command in your project folder that has an .npmrc file in it:

npx vsts-npm-auth -config .npmrc 
like image 101
LCIII Avatar answered Sep 20 '22 14:09

LCIII


Use npm install --registry https://registry.npmjs.org instead of npm install

like image 34
dhiraka Avatar answered Sep 18 '22 14:09

dhiraka