升级Node v18和npm v9后执行npm publish遇授权错误求助
问题:升级Node v18/npm v9后npm publish提示需登录Nexus仓库
升级到Node.js v18和npm v9后,执行npm publish发布包时收到错误提示,要求登录https://some-package.com:48082/nexus/repository/path1/并通过npm adduser授权本机。
当前.npmrc配置内容
用户级.npmrc
//some-package.com:48082/nexus/repository/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem //some-package.com:48082/nexus/repository/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem //registry.npmjs.org/:_authToken=<auth_token>
项目级.npmrc
@fortawesome:registry=https://npm.fontawesome.com/ @scope1:registry=https://some-package.com:48082/nexus/repository/path1/ @scope2:registry=https://some-package.com:48082/nexus/repository/path2/ //npm.fontawesome.com/:_authToken=<auth_token> //some-package.com:48082/nexus/repository/:_auth=<auth> strict-ssl=false
解决方案
针对目标仓库执行
npm adduser授权:npm adduser --registry=https://some-package.com:48082/nexus/repository/path1/按提示输入用户名、密码、邮箱,完成本机授权。
校验
_auth字段有效性:npm v9对认证格式要求更严格,确保//some-package.com:48082/nexus/repository/:_auth是用户名:密码的base64编码字符串,若不确定可重新生成:echo -n "用户名:密码" | base64将生成的字符串替换现有
_auth值。细化证书配置路径:用户级.npmrc的证书配置是针对根仓库路径,npm v9可能无法匹配到子路径
path1/path2,建议调整为://some-package.com:48082/nexus/repository/path1/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem //some-package.com:48082/nexus/repository/path1/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem //some-package.com:48082/nexus/repository/path2/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem //some-package.com:48082/nexus/repository/path2/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem验证配置:执行
npm config list查看生效配置,确认目标仓库的认证、证书项已正确加载。
内容的提问来源于stack exchange,提问作者Visovan Mihai
相关产品推荐
相关产品推荐

