node.js “npm 配置设置注册表 https://registry.npmjs.org/”在 windows bat 文件中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22385092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:01:30  来源:igfitidea点击:

"npm config set registry https://registry.npmjs.org/" is not working in windows bat file

node.jsbatch-filenpm

提问by mopduan

I create a.bat on windows 7, the content of a.bat is:

我在windows 7上创建了a.bat,a.bat的内容是:

@echo off
npm config set registry https://registry.npmjs.org/

and then run a.bat, but not working, I find the word "set" is special keyword for npm and bat, is there any methods to resolve this question?

然后运行a.bat,但不工作,我发现“set”这个词是npm和bat的特殊关键字,有什么方法可以解决这个问题吗?

回答by Gntem

You shouldn't change the npm registry using .batfiles. Instead try to use modify the .npmrcfile which is the configuration for npm. The correct command for changing registry is

您不应该使用.bat文件更改 npm 注册表。而是尝试使用修改.npmrc作为npm. 更改注册表的正确命令是

npm config set registry <registry url>

npm config set registry <registry url>

you can find more information with npm help configcommand, also check for privileges when and if you are running .batfiles this way.

您可以使用npm help config命令找到更多信息,还可以在何时以及是否以.bat这种方式运行文件时检查权限。

回答by Venkat.R

We can also run npm install with registryoptions for multiple custom registry URLs.

我们还可以使用registry多个自定义注册表 URL 的选项运行 npm install 。

npm install --registry=https://registry.npmjs.org/ 
npm install --registry=https://custom.npm.registry.com/ 

回答by jsmartfo

You can change using the .bat make sure you run the call command prior, hopefully this helps anyone in future making similar .bat commands

您可以使用 .bat 进行更改,确保您事先运行了 call 命令,希望这有助于将来制作类似 .bat 命令的任何人

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

回答by Gilberto Alexandre

On version 4.4.1, you can use:

在 4.4.1 版本上,您可以使用:

npm config set @myco:registry http://reg.example.com

Where @myco is your package scope. You can install package in this way:

@myco 是您的包范围。您可以通过以下方式安装软件包:

npm install @myco/my-package

ref: https://docs.npmjs.com/misc/scope

参考:https: //docs.npmjs.com/misc/scope

回答by Kavya Rani

Probably I am too late to answer. But if anybody need it, following works fine, as I have used it a lot of times.

可能我回答得太晚了。但是如果有人需要它,下面的效果很好,因为我已经用过很多次了。

npm config set registry=https://registry.npmjs.com/

回答by madKakoo

On npm version 3.7.3

在 npm 版本 3.7.3 上

npm set registry=http://whatever/

npm set registry=http://whatever/

回答by rakesh

By executing your .bat you are setting config for only that session not globally. When you open and another cmd prompt and run npm installthat config will not set for this session so modify your .bat file as

通过执行您的 .bat,您只为该会话设置了配置,而不是全局设置。当您打开另一个 cmd 提示符并运行npm install该配置时,不会为此会话设置该配置,因此将您的 .bat 文件修改为

@echo off
npm config set registry https://registry.npmjs.org/
@cmd.exe /K

回答by Ivix4u

  1. Set npm registry globally

    use the below command to modify the .npmrc config file for the logged in user

    npm config set registry <registry url>

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

  1. 全局设置 npm 注册表

    使用以下命令修改登录用户的 .npmrc 配置文件

    npm config set registry <registry url>

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



  1. Set npm registry Scope

    Scopes allow grouping of related packages together. Scoped packages will be installed in a sub-folder under node_modulesfolder.

    Example: node_modules/@my-org/packagaename

    To set the scope registry use: npm config set @my-org:registry http://example.reg-org.com

    To install packages using scope use: npm install @my-org/mypackage

    whenever you install any packages from scope @my-orgnpm will search in the registry setting linked to scope @my-orgfor the registry url.

  1. 设置 npm 注册表范围

    范围允许将相关包分组在一起。作用域包将安装在node_modules文件夹下的子文件夹中。

    示例node_modules/@my-org/packagaename

    要设置范围注册表,请使用: npm config set @my-org:registry http://example.reg-org.com

    要使用范围安装软件包,请使用: npm install @my-org/mypackage

    每当您从范围@my-org安装任何软件包时,npm 都会在链接到范围@my-org的注册表设置中搜索注册表 URL。



  1. Set npm registry locally for a project

    To modify the npm registry only for the current project. create a file inside the root folder of the project as .npmrc

    Add the below contents in the file

  1. 在本地为项目设置 npm 注册表

    仅为当前项目修改 npm 注册表。在项目的根文件夹中创建一个文件作为.npmrc

    在文件中添加以下内容

   registry = 'https://registry.npmjs.org/'

回答by Hamid Shariati

2.name can no longer contain capital letters

don't use capital letters for your package:

不要为您的包裹使用大写字母:

npm install --save uex

use this:

用这个:

npm install --save vuex

回答by Srichakra

You might not be able to change npm registry using .batfile as Gntempointed out. But I understand that you need the ability to automate changing registries. You can do so by having your .npmrcconfigs in separate files (say npmrc_jfrog& npmrc_default) and have your .batfiles do the copying task.

您可能无法.batGntem指出的那样使用文件更改 npm 注册表。但我知道您需要能够自动更改注册表。您可以通过将您的.npmrc配置放在单独的文件中(比如npmrc_jfrognpmrc_default)并让您的.bat文件执行复制任务来实现。

For example (in Windows): Your default_registry.batwill have

例如(在 Windows 中):您default_registry.bat将拥有

xcopy /y npmrc_default .npmrc

and your jfrog_registry.batwill have

jfrog_registry.bat会拥有

xcopy /y npmrc_jfrog .npmrc

Note:/ysuppresses prompting to confirm that you want to overwrite an existing destination file.

注意:/y禁止提示确认您要覆盖现有目标文件。

This will make sure that all the config properties (registry, proxy, apiKeys, etc.) get copied over to .npmrc.

这将确保所有配置属性(注册表、代理、apiKeys 等)都被复制到.npmrc.

You can read more about xcopy here.

您可以在此处阅读有关 xcopy 的更多信息。