简体   繁体   English

带有特殊字符的 npm 私有注册表用户名

[英]npm private registry username with special characters

I'm trying to access a private npm registry that is hosted in a remote server.我正在尝试访问托管在远程服务器中的私有 npm 注册表。 I have to access it using username and password.我必须使用用户名和密码访问它。 There is no proxy on my side.我这边没有代理。

But, the username and password which I use, have URL unsafe characters.但是,我使用的用户名和密码具有 URL 不安全字符。 I've tried adduser , npmjs , scl but I'm unable to configure the credentials :我试过addusernpmjsscl但我无法配置凭据:

npm WARN Name may not contain non-url-safe chars

I've tried to set NPM_USER and NPM_PASS directly from command line.我试图直接从命令行设置NPM_USERNPM_PASS I'm able to set the former but the later fails.我可以设置前者,但后者失败了。 Even if I use a simple password and try :即使我使用简单的密码并尝试:

npm login

It fails with the same error since NPM_USER has a @由于NPM_USER@

I'm using npmrc to switch between public and private registries.我正在使用npmrc在公共和私有注册表之间切换。 I want to avoid tools like Nexus/JFrog .我想避免使用Nexus/JFrog类的工具。

npm version - 4.0.5 and OS is Windows 7 npm 版本 - 4.0.5 和操作系统是 Windows 7

What am I missing here?我在这里缺少什么?

So to recap, your problem is that your private registry uses email addresses for user names, which is not currently supported by the npm command line tools.总结一下,您的问题是您的私有注册表使用电子邮件地址作为用户名,npm 命令行工具目前不支持这种方式。 You need a way to provide your user name without running npm adduser or npm login .您需要一种无需运行npm addusernpm login即可提供用户名的方法。 I don't know which registry you are using, but I had the same problem with Inedo's Proget .我不知道您使用的是哪个注册表,但我在使用Inedo 的 Proget 时遇到了同样的问题。

EDIT: I have the same problem in March 2021, with Azure Artifacts in Azure DevOps , because the npm command-line tools still don't allow @ in usernames, and also the vsts-npm-auth command-line tool does not work on Linux or Mac .编辑:我在 2021 年 3 月遇到了同样的问题, Azure DevOps 中的 Azure Artifacts ,因为 npm 命令行工具仍然不允许在用户名中使用@ ,而且vsts-npm-auth命令行工具也不起作用Linux 或 Mac I have also had the same problem with Artifactory.我在 Artifactory 上也遇到了同样的问题。

If you're using a private registry and you are using scopes to separate the different registries, you can create an .npmrc file that looks like this:如果您使用的是私有注册表并且使用范围来分隔不同的注册表,则可以创建一个.npmrc文件:

#Settings for @SCOPENAME
@SCOPENAME:registry=https://DOMAIN/FEED/
//DOMAIN/FEED/:username=USER@DOMAIN
//DOMAIN/FEED/:_password=BASE64(PASSWORD)
//DOMAIN/FEED/:email=EMAIL_ADDRESS
//DOMAIN/FEED/:always-auth=true

#Settings for @OTHERSCOPENAME
@OTHERSCOPENAME:registry=...

This next bit might be important, but it depends on your registry's preferred feed urls: I couldn't get this to work properly without the trailing / so take care to try both with and without it.下一点可能很重要,但它取决于您的注册中心的首选提要网址:如果没有尾随/ ,我无法使其正常工作,因此请注意尝试使用和不使用它。

An easy way to get the base64 encoding of your password is to run:获取密码的 base64 编码的一种简单方法是运行:

echo -n 'PASSWORD' | base64

EDIT: For some registries, like Azure Artifacts , you need to use a personal access token instead of your normal password.编辑:对于某些注册表,例如Azure Artifacts ,您需要使用个人访问令牌而不是普通密码。 Look up the instructions for your registry about how to create a token.查找有关如何创建令牌的注册表说明。

EDIT: It's also possible to have the .npmrc file without scopes, if you are only using one registry:编辑:如果您只使用一个注册表,也可以使用没有作用域的.npmrc文件:

# Global settings
registry=https://DOMAIN/FEED/
//DOMAIN/FEED/:username=USER@DOMAIN
//DOMAIN/FEED/:_password=BASE64(PASSWORD)
//DOMAIN/FEED/:email=EMAIL_ADDRESS
//DOMAIN/FEED/:always-auth=true

You just have to login normally without the '@'.您只需要在没有“@”的情况下正常登录即可。 Unfortunately its kind of hard to find this information on npm.不幸的是,很难在 npm 上找到这些信息。 When you publish packages is when you need to use the @ symbol.当您发布包时,您需要使用 @ 符号。

If this is for a public organization and for example I have an organization name "@seatbelt" so a package name I publish under is "@seatbelt/core".如果这是针对公共组织的,例如我有一个组织名称“@seatbelt”,那么我发布的包名称是“@seatbelt/core”。 The package is installed by typing "npm install @seatbelt/core".通过键入“npm install @seatbelt/core”安装该软件包。

If this is just for you personally to publish private packages you publish private package names with the format "@username/project-name".如果这只是为了您个人发布私有包,您可以使用“@username/project-name”格式发布私有包名称。 Like the example above, once published you can install the package by doing "npm install @username/project-name"像上面的例子一样,一旦发布,你可以通过执行“npm install @username/project-name”来安装包

More information can be found at https://docs.npmjs.com/private-modules/intro更多信息可以在https://docs.npmjs.com/private-modules/intro找到

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

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