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

前端 未结 29 1004
隐瞒了意图╮
隐瞒了意图╮ 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:33

    I solved this problem this way:

    1. I run this command:

      npm config set strict-ssl false
      
    2. Then set npm to run with http, instead of https:

      npm config set registry "http://registry.npmjs.org/"
      
    3. Then I install packages using this syntax:

      npm --proxy http://username:password@cacheaddress.com.br:80 install packagename
      

    Skip the username:password part if proxy doesn't require you to authenticate

    EDIT: A friend of mine just pointed out that you may get NPM to work behind a proxy by setting BOTH HTTP_PROXY and HTTPS_PROXY environment variables, then issuing normally the command npm install express (for example)

    EDIT2: As @BStruthers commented, keep in mind that passwords containing "@" wont be parsed correctly, if contains @ put the entire password in quotes

提交回复
热议问题