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

前端 未结 10 1455
自闭症患者
自闭症患者 2020-12-12 10:08

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

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

and then run a.bat, but

相关标签:
10条回答
  • 2020-12-12 10:20
    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. Set npm registry Scope

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

      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-org npm will search in the registry setting linked to scope @my-org for the registry 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

       registry = 'https://registry.npmjs.org/'
    
    0 讨论(0)
  • 2020-12-12 10:28

    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/
    
    0 讨论(0)
  • 2020-12-12 10:28

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

    @echo off
    npm config set registry https://registry.npmjs.org/
    @cmd.exe /K
    
    0 讨论(0)
  • 2020-12-12 10:30

    You shouldn't change the npm registry using .bat files. Instead try to use modify the .npmrc file which is the configuration for npm. The correct command for changing registry is

    npm config set registry <registry url>

    you can find more information with npm help config command, also check for privileges when and if you are running .bat files this way.

    0 讨论(0)
  • 2020-12-12 10:34

    On npm version 3.7.3

    npm set registry=http://whatever/

    0 讨论(0)
  • 2020-12-12 10:39

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

    For example (in Windows): Your default_registry.bat will have

    xcopy /y npmrc_default .npmrc
    

    and your jfrog_registry.bat will have

    xcopy /y npmrc_jfrog .npmrc
    

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

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

    You can read more about xcopy here.

    0 讨论(0)
提交回复
热议问题