Is there a way to make npm install (the command) to work behind proxy?

前端 未结 29 974
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 08:08

Read about a proxy variable in a .npmrc file but it does not work. Trying to avoid manually downloading all require packages and installing.

相关标签:
29条回答
  • 2020-11-22 08:25

    vim ~/.npmrc in your Linux machine and add following. Don't forget to add registry part as this cause failure in many cases.

    proxy=http://<proxy-url>:<port>
    https-proxy=https://<proxy-url>:<port>
    registry=http://registry.npmjs.org/
    
    0 讨论(0)
  • 2020-11-22 08:26

    A lot of applications (e.g. npm) can use proxy setting from user environment variables.

    You can just add to your environment following variables HTTP_PROXY and HTTPS_PROXY that will have the same value for each one

    http://user:password@proxyAddress:proxyPort

    For example if you have Windows you can add proxy as follow:

    0 讨论(0)
  • 2020-11-22 08:27

    There has been many answers above for this question, but none of those worked for me. All of them mentioned to add http:// prefix. So I added it too. All failed.

    It finally works after I accidentally removed http:// prefix. Final config is like this:

    npm config set registry http://registry.npmjs.org/
    npm config set http-proxy ip:port
    npm config set https-proxy ip:port
    npm config set proxy ip:port
    npm set strict-ssl false
    

    I don't know the logic behind this, but it worked. If none of answers above works for you, maybe you can have a try on this way. Hope this one is useful.

    0 讨论(0)
  • 2020-11-22 08:29

    This works for me in Windows:

    npm config set proxy http://domain%5Cuser:pass@host:port
    

    If you are not in any domain, use:

    npm config set proxy http://user:pass@host:port
    

    If your password contains special characters such as ",@,: and so on, replace them by their URL encoded values. For example "->%22, @->%40, :->%3A. %5C is used for the character \.

    0 讨论(0)
  • 2020-11-22 08:29

    This worked for me-

    npm config set proxy http://proxy.company.com:8080
    npm config set https-proxy http://proxy.company.com:8080
    npm set strict-ssl=false
    
    0 讨论(0)
  • 2020-11-22 08:31

    Though i set proxy with config, problem was not solved but after This one worked for me:

    npm --https-proxy http://XX.AA.AA.BB:8080 install cordova-plugins

    npm --proxy http://XX.AA.AA.BB:8080 install

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