You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 13:18:00