发布时间:2023-04-21 文章分类:WEB开发, 电脑百科 投稿人:李佳 字号: 默认 | | 超大 打印

场景:

执行npm install时提示Unable to authenticate

Password:
Email: (this IS public) xx@qq.com
Logged in as uploader on http://192.168.xx.xxx:8074/repository/npm-internal/.
PS D:\GitworkspaceUi\gisquest-cloud-ui-workcenter> npm install
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2023-01-04T06_05_27_843Z-debug.log     
PS D:\GitworkspaceUi\gisquest-cloud-ui-workcenter> 

问题原因:

执行npm install到仓库拉取代码时需要认证,现在是认证不通过,因此报错 

现象:

浏览器直接访问仓库,然后使用公司给的账号和密码登录是正常的,说明账号密码是正确的

http://192.168.xx.xxx:8074/repository/npm-internal/.

解决方法:

先执行npm config list,找到.npmrc的位置

PS D:\GitworkspaceUi\gisquest-cloud-ui-workcenter> npm config list
; cli configs
metrics-registry = "http://192.168.xxx.xxx:8073/repository/npm-all/"
scope = ""
user-agent = "npm/6.14.12 node/v14.16.1 win32 x64"

; userconfig C:\Users\Administrator\.npmrc

 方法一(网上的仅供参考):

打开后大概如下效果

npm install 提示Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager“

 删掉第二行

 //192.168.xx.xx:8073/repository/npm-all/:_authToken=NpmToken.1ee55b58-d164-3b43-a731-xxxxxx

 重新执行登录

npm login --registry=http://192.168.xx.xxx:8073/repository/npm-internal/

  方法二:直接删掉.npmrc

npm config set registry http://192.168.xx.xxxx:8073/repository/npm-all/ 

npm config set //192.168.xx.xxx:8073/repository/npm-all/:_authToken=NpmToken.1ee55b58-d164-3b43-a731-xxxxx

说明:上面第一条命令是注册仓库的位置,第二条是仓库的的认证token

这里的token是从同事(他那里是正常).npmrc文件中复制过来的

然后执行npm install正常了