NPM 始终使用 AWS Codeartifact

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

我的本地计算机上有一些不同的项目。其中一些使用AWS Codeartifact下载AWS Codeartifact中的私有依赖项,而另一些则不使用。使用 AWS Codeartifact 的项目使用 Yarn 管理其依赖项,而我不使用 AWS Codeartifact 的项目使用 NPM 管理其依赖项。

当我在 NPM 中运行一个简单的命令时,例如:

npm install nanoid

npm 尝试连接到我的 AWS Codeartifact,但出现错误:

Unable to authenticate, need: Bearer realm="domain-npm-repo/npm-repo", Basic realm="domain-npm-repo/npm-repo"

如何配置我的机器以仅将 AWS Codearticaft 用于我想要的项目?

其他配置:

我的机器是 Windows 10,我使用我的凭据在全局安装了 aws-sdk。

amazon-web-services npm yarnpkg aws-codeartifact
4个回答
19
投票

我运行命令解决了它:

npm config set registry https://registry.npmjs.org/

它将我的 npm 注册表设置回默认值,并使用 npm 注册表而不是我的 aws codeartifact 注册表。


6
投票

假设您使用

aws codeartifact login --tool npm --repository my-repo --domain my-domain
登录 AWS,您应该使用更精细的方法,使用以下命令:

# get endpoint 
endpoint = aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format npm

# set a scoped registry
npm config set registry endpoint --scope=@my-package <- this is what you want

# get token
token = aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --repository my_repo

# set token
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:_authToken=token

# always truth
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:always-auth=true

这些命令是对

aws codeartifact login --tool npm --repository my-repo --domain my-domain
更多信息)的解构,不同之处在于,不是在
registry
文件(用于设置 npm 的配置)中设置常规
.npmrc
,而是设置一个 作用域注册表更多信息)。 通过这种方式,您将能够从您想要的来源获取您的包。


0
投票

将来是否有人会登陆此页面。上述解决方案都不适合我。有效的方法是在我的

publishConfig.registry
package.json
属性中添加一个尾部斜杠。


0
投票

作为虚拟修复 - 当您不想使用 codeartifact 时,可以删除 .npmrc 文件中的所有内容。但是每次运行 codeartifact 命令时该文件都会更新,因此每次要运行非 codeartifact 项目时都必须清理该文件。

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