简体   繁体   English

NPM 始终使用 AWS Codeartifact

[英]NPM always uses AWS Codeartifact

I have some different projects in my local machine.我的本地机器上有一些不同的项目。 Some of then uses AWS Codeartifact to download private dependencies in AWS Codeartifact, and others do not use.其中一些使用 AWS Codeartifact 下载 AWS Codeartifact 中的私有依赖项,而另一些则不使用。 The projects that uses AWS Codeartifact manage their dependencies with Yarn, and my projects that do not uses AWS Codeartifact manage their dependencies with NPM.使用 AWS Codeartifact 的项目使用 Yarn 管理它们的依赖项,而我不使用 AWS Codeartifact 的项目使用 NPM 管理它们的依赖项。

When i run a simple command in NPM like:当我在 NPM 中运行一个简单的命令时,例如:

npm install nanoid

The npm tries to connect to my AWS Codeartifact and it gives an error: npm 尝试连接到我的 AWS Codeartifact 并给出错误:

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

How can i configure my machine to use AWS Codearticaft only to the projects i want?如何将我的机器配置为仅将 AWS Codearticaft 用于我想要的项目?

Other Configurations:其他配置:

My machine is a Windows 10, and i have aws-sdk installed globally with my credentials.我的机器是 Windows 10,我使用我的凭据全局安装了 aws-sdk。

Assuming you are using aws codeartifact login --tool npm --repository my-repo --domain my-domain to login into aws you should use a more granular approach use the following commands:假设您使用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

These commands are a deconstruction of aws codeartifact login --tool npm --repository my-repo --domain my-domain ( more info ), with the difference that instead of setting a general registry at your .npmrc file (used to set configurations for your npm) will set a scoped registry ( more info ).这些命令是aws codeartifact login --tool npm --repository my-repo --domain my-domain更多信息)的解构,不同之处在于不是在您的.npmrc文件中设置通用registry (用于设置配置为您的 npm)将设置一个范围注册表更多信息)。 In this way you will be able to have you fetch your packages from the sources you want.通过这种方式,您将能够从您想要的来源获取您的包。

I solved it running the command:我解决了它运行命令:

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

It set my npm registry back to the default value and uses the npm registry instead of my aws codeartifact registry.它将我的 npm 注册表设置回默认值,并使用 npm 注册表而不是我的 aws codeartifact 注册表。

Should anybody land on this page in the future.将来是否有人登陆此页面。 None of the above solutions worked for me.以上解决方案都不适合我。 What did work is adding a trailing slash in the publishConfig.registry property of my package.json .起作用的是在我的package.jsonpublishConfig.registry属性中添加一个斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM