如何使用 gitlab ci 发布私有 npm 包? [英] How do I publish a private npm package with gitlab ci?

查看:27
本文介绍了如何使用 gitlab ci 发布私有 npm 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Gitlab CI 发布一个私有 npm 包.

I want to publish a private npm package with Gitlab CI.

我为我的 npm 用户创建了一个身份验证令牌,并在我的 Gitlab CI 设置中将其设置为变量 NPM_TOKEN.

I've created an auth token for my npm user and set it as a variable NPM_TOKEN in my Gitlab CI settings.

然后,该作业会使用注册表和身份验证令牌创建一个 .npmrc 文件.

The job then creates an .npmrc file with the registry and the auth token.

- npm run build && npm run build:es6
- echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'>.npmrc
- npm publish

作业失败并显示以下消息:

The job fails with this message:

npm ERR! code ENEEDAUTH
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using `npm adduser`

是否可以仅使用身份验证令牌进行发布?

Is it possible to publish with only an auth token?

推荐答案

正如@Amityo所说,与其手动编辑npmrc文件,

As @Amityo said, rather than manually editing the npmrc file,

npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}

是要走的路,否则你可能会编辑错误的 npmrc 文件.

is the way to go, because otherwise you may be editing the wrong npmrc file.

如果您仍然收到身份验证错误,并且确定令牌是正确的,请检查您的注册表 URL.你可以运行

If you are still getting an authentication error, and are certain that the token is correct, check your registry URL. You can run

npm publish --verbose

其输出将包括类似的行

npm verb getPublishConfig { registry: 'https://.......' }
npm verb mapToRegistry no registry URL found in name for scope @boxine
npm verb publish registryBase https://.......

如果您要发布到 npmjs.org,则 URL(上面的 .......)应该是 https://registry.npmjs.org/ .

If you are publishing to npmjs.org, the URL (....... above) should be https://registry.npmjs.org/ .

如果此注册表 URL 不合适,请在您的 npmrc 文件中查找其他 URL.还要确保您没有覆盖 package.json 文件中的注册表!您可以在该文件中搜索 publishConfig.

If this registry URL does not fit, look in your npmrc file for a different one. Also make sure you didn't override the registry in your package.json file! You can search for publishConfig in that file.

这篇关于如何使用 gitlab ci 发布私有 npm 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆