npm install安装失败Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager“

        本地Nexus私服已配置账号密码认证,并创建专用仓库账号,通过网页端可以正常访问。在命令行中执行 npm login 成功后,使用 npm install 安装依赖报 Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"。经过仔细研究,发现是 realms 配置原因。

目录

1、背景

1.1、npm login登录成功

1.2、npm install报认证失败

1.3、查看Node.js版本信息

2、修改Sonatype Nexus Realms配置

2.1、添加Realms 

2.2、验证配置是否生效

3、实践总结


运行环境:

1、背景

        IT Developer 的终极,至少要掌握前端、后端、数据库等必备软件的基础知识点,并可以独立搭建开发环境、运行环境。本文将使用Sonatype Nexus搭建 npm私服的一次尝试,并把遇到的问题整理。

1.1、npm login登录成功

npm login

 登录成功日志:

npm WARN adduser `adduser` will be split into `login` and `register` in a future version. `adduser` will become an alias of `register`. `login` (currently an alias) will become its own command.
npm notice Log in on http://私服IP:私服端口/repository/npm-repos/
Username: 专用账号
Password: 账号密码
Email: (this IS public) () 绑定邮箱
Logged in as h5-developer on http://私服IP:私服端/repository/npm-repos/.

1.2、npm install报认证失败

npm install

安装失败日志: 

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

尝试查找一些博文,说是要删除 .npmrc 文件中的 _authToken 行配置,经过实测不行!

 

1.3、查看Node.js版本信息

npm version

2、修改Sonatype Nexus Realms配置

        结合错误信息 Unable to authenticate, need: BASIC realm,并查阅各方资料,将范围缩小到 Sonatype Nexus 的 Realms配置。

2.1、添加Realms 

        使用 admin 用户登录,在菜单 系统设置 >> Security >> Realms  添加可用领域 npm Beaner Token Realm,保存。

2.2、验证配置是否生效

再次打开命令终端,执行 npm install ,可以看到成功下载。

3、实践总结

        同一个报错,可能有种原因引起,本文遇到的 Realms 授权配置原因引起,在此做记录,供有需要码友参考。


附录:

猜你喜欢

转载自blog.csdn.net/Sn_Keys/article/details/131022273
今日推荐