简体   繁体   English

如何在使用 git remote url 进行 npm install 时指定注册表?

[英]How to specify registry while doing npm install with git remote url?

I want to be able to clone a git repository using a URL as specified here我希望能够使用此处指定的 URL 克隆 git 存储库

<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>]

I am getting an error saying我收到一条错误消息

npm ERR! npm 错误! 404 Registry returned 404 for GET on https://registry.npmjs.org/XYZ 404 注册表为https://registry.npmjs.org/XYZ 上的GET 返回 404

So I should also be able to specify the registry while doing since modules are supposed to be picked up from a internal repository.所以我也应该能够在做的时候指定注册表,因为模块应该从内部存储库中获取。

Is it possible to specify registry while doing npm install with git remote url ?是否可以在使用git remote url进行npm install指定注册表

npm gets its config settings from the command line, environment variables, and npmrc files. npm从命令行、环境变量和 npmrc 文件中获取其配置设置。 You can try to specify registry in a npmrc file, and module in the command line.您可以尝试在 npmrc 文件中指定注册表,并在命令行中指定模块。 To change registry, you can use command:要更改注册表,您可以使用命令:

npm config set registry <registry url>

You can also change configs with the help of -- argument.您还可以在--参数的帮助下更改配置。 Putting --foo bar on the command line sets the foo configuration parameter to " bar ".--foo bar放在命令行上--foo bar foo 配置参数设置为“ bar ”。 So you can try something like that:所以你可以尝试这样的事情:

 npm install http://git.repo.url --registry=https://your.registry.local/

Not the best way but If you are using mac or linux even in you can set alias for different registries.不是最好的方法,但如果您使用的是 mac 或 linux,您甚至可以为不同的注册表设置别名。

##############NPM ALIASES######################
alias npm-default='npm config set registry https://registry.npmjs.org'
alias npm-sinopia='npm config set registry http://localhost:4873/'

Yes, you need to use:是的,您需要使用:

npm config set registry <registry url>.

to make sure you install your package from the registry inside your company.确保从公司内部的注册表安装包。

If you are doing npm -i -g , this is to install globally.如果您正在执行npm -i -g ,则这是全局安装。

you need to do:你需要做:

npm -g config set registry <registry url>

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

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