npm v8 和 npm v9 之间的 npm 配置迁移

问题描述 投票:0回答:1

我从

node 16.19.1
的 npm 版本
8.19.1
迁移到节点
20.5.1
,在我的 github 操作工作流程中使用 npm 版本
9.8.0
,该工作流程将 npm 发布到版本 OSS 3.41.1 的 Nexus 存储库。

我的 npm v8.19.1 初始配置如下:

npm config set registry="http://nexus.example.com:8081/nexus/repository/example-package/"
npm config set _auth="MY_BASE_64_TOKEN"
npm config set email="[email protected]"
npm config set always-auth=true
npm config set strict-ssl=false

通过这个配置我可以成功执行

npm publish

npm v9 引入了影响我的配置的重大更改,例如:

  • always-auth
    不是有效的 npm 选项
  • _auth
    不能用作 npm 配置 - 它必须是 URL 注册表的一部分
  • auth-type
    将默认值从
    legacy
    更改为
    web

所以我将配置更改为:

npm config set email="[email protected]"
npm config set strict-ssl=false
npm config set auth-type=legacy
npm config set registry="http://nexus.example.com:8081/nexus/repository/example-package/"
npm config set //nexus.example.com:8081/nexus/repository/example-package/:_auth=MY_BASE_64_TOKEN

和之后

npm publish
我有这些错误:

npm verb Linux 5.15.0-1041-azure
npm verb node v20.5.1
npm verb npm  v9.8.0
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm verb exit 1
npm verb code 1

你知道我做错了什么或者我错过了什么吗?

npm github-actions nexus npm-publish
1个回答
0
投票


正如您所注意到的,

npm
v9 引入了重大更改。我在我的 GitLab CI 环境中遇到了同样的问题,但我通过实施下面描述的步骤设法克服了这些问题。
在展示我遵循的步骤之前,我想强调一下,所确定的解决方案基于 使用身份验证基本身份验证,并且已针对下图所示的系统和平台进行了测试:

  • node:18.18.0
    Docker 镜像
  • Sonatype Nexus 存储库 OSS 3.59.0-01
  • npm v9.8.1

根据您的参数,将要实施的步骤报告如下:

  • echo "[email protected]" > /root/.npmrc
  • echo "always-auth=true" > /root/.npmrc
  • echo "//nexus.example.com:8081/nexus/repository/_auth=<username:password>" > /root/.npmrc
  • npm publish --registry=http://nexus.example.com:8081/nexus/repository/example-package/

注意! 正如官方文档所述,

<username:password>
值必须表示为base64-encoding

© www.soinside.com 2019 - 2024. All rights reserved.