npm 私有源无法下载解决方案

问题描述

最近在使用npm install或者yarn install时会出现

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

解决思路

  • 根据报错内容 401可能是认证问题,但是私服nexus下载依赖是不需要认证的(权限已经配置)所以排除此种可能
    npm 私有源无法下载解决方案_第1张图片

  • 使用npm cache clear --force清楚缓存 同时删除package-lock.json或者yarn-lock.jsonnode_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已经升级,初步验证可以下载最新的依赖包,如有问题请及时反馈!谢谢!

你可能感兴趣的:(node,centos7,devops)