问题描述
最近在使用npm install
或者yarn install
时会出现
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
解决思路
-
根据报错内容 401可能是认证问题,但是私服nexus下载依赖是不需要认证的(权限已经配置)所以排除此种可能
-
使用
npm cache clear --force
清楚缓存 同时删除package-lock.json
或者yarn-lock.json
及node_modules
文件夹 重新运行npm install
npm cache clear --force
rm package-lock.json (rm yarn-lock.json)
rm -r node_modules
npm install
- 如果上述方法未能解决问题,打开本地的
.npmrc
或者.yarnrc
文件,一般路径在当前用户目录下。
sass_binary_site=http://xxx:8081/repository/node-sass-host/
registry=http://xxx:8081/repository/npm-group/
config=registry
xxx:8081/repository/npm-group/:_authToken=NpmToken
注
nexus已经升级,初步验证可以下载最新的依赖包,如有问题请及时反馈!谢谢!