Node.js 有没有办法让npm安装(命令)在代理之后工作?

Node.js 有没有办法让npm安装(命令)在代理之后工作?,node.js,npm,Node.js,Npm,了解.npmrc文件中的代理变量,但它不起作用。试图避免手动下载所有require软件包并进行安装。您是否尝试了命令行选项而不是.npmrc文件 我认为类似于npm——代理http://proxy-server:8080/ 安装{package name}对我有效 我还看到了以下内容: npm配置集代理http://proxy-server:8080/设置npm代理 对于HTTP: npm配置集代理http://proxy_host:port 对于HTTPS: 如果存在https代理地址,请使

了解
.npmrc
文件中的代理变量,但它不起作用。试图避免手动下载所有require软件包并进行安装。

您是否尝试了命令行选项而不是
.npmrc
文件

我认为类似于
npm——代理http://proxy-server:8080/ 安装{package name}
对我有效

我还看到了以下内容:
npm配置集代理http://proxy-server:8080/

设置
npm
代理

对于
HTTP

npm配置集代理http://proxy_host:port
对于
HTTPS

如果存在https代理地址,请使用https代理地址

npm config set https-proxy https://proxy.company.com:8080
否则重用http代理地址

npm config set https-proxy http://proxy.company.com:8080

注意:https代理没有
https
作为协议,而是
http

我这样解决了这个问题:

  • 我运行以下命令:

    npm config set strict ssl false
    
  • 然后将npm设置为使用http而不是https运行:

    npm配置集注册表”http://registry.npmjs.org/"
    
  • 然后,我使用以下语法安装软件包:

    npm——代理http://username:password@cacheaddress.com.br:80安装packagename
    
  • 如果代理服务器不要求您进行身份验证,请跳过
    用户名:密码
    部分

    编辑:我的一位朋友刚刚指出,您可以通过设置HTTP\u proxy和HTTPS\u proxy环境变量,然后正常发出命令NPM install express来让NPM在代理之后工作(例如)


    EDIT2:正如@BStruthers所评论的,请记住,包含“@”的密码不会被正确解析,如果包含“@”,请将整个密码置于引号中。如果有疑问,请尝试所有这些命令,就像我所做的那样:

    npm配置集注册表http://registry.npmjs.org/
    配置集代理http://myusername:mypassword@美国某公司代理:8080
    npm配置集https代理http://myusername:mypassword@美国某公司代理:8080
    npm配置设置严格ssl错误
    设置HTTPS\u代理=http://myusername:mypassword@美国某公司代理:8080
    设置HTTP\U代理=http://myusername:mypassword@美国某公司代理:8080
    导出HTTPS\u代理=http://myusername:mypassword@美国某公司代理:8080
    导出HTTP\U代理=http://myusername:mypassword@美国某公司代理:8080
    导出http\U代理=http://myusername:mypassword@美国某公司代理:8080
    npm——代理http://myusername:mypassword@美国某公司代理:8080\
    --没有ssl——不安全的-g安装
    
    =======

    更新 将您的设置放入
    ~/.bashrc
    ~/.bash\u profile
    中,这样您就不必担心每次打开新的终端窗口时的设置了

    如果你的公司和我的一样,我必须经常更改密码。因此,我在我的~/.bashrc或~/.bash_配置文件中添加了以下内容,以便无论何时打开终端,我都知道我的npm是最新的

  • 只需将以下代码粘贴到
    ~/.bashrc
    文件的底部:

    ######################
    # User Variables (Edit These!)
    ######################
    username="myusername"
    password="mypassword"
    proxy="mycompany:8080"
    
    ######################
    # Environement Variables
    # (npm does use these variables, and they are vital to lots of applications)
    ######################
    export HTTPS_PROXY="http://$username:$password@$proxy"
    export HTTP_PROXY="http://$username:$password@$proxy"
    export http_proxy="http://$username:$password@$proxy"
    export https_proxy="http://$username:$password@$proxy"
    export all_proxy="http://$username:$password@$proxy"
    export ftp_proxy="http://$username:$password@$proxy"
    export dns_proxy="http://$username:$password@$proxy"
    export rsync_proxy="http://$username:$password@$proxy"
    export no_proxy="127.0.0.10/8, localhost, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16"
    
    ######################
    # npm Settings
    ######################
    npm config set registry http://registry.npmjs.org/
    npm config set proxy "http://$username:$password@$proxy"
    npm config set https-proxy "http://$username:$password@$proxy"
    npm config set strict-ssl false
    echo "registry=http://registry.npmjs.org/" > ~/.npmrc
    echo "proxy=http://$username:$password@$proxy" >> ~/.npmrc
    echo "strict-ssl=false" >> ~/.npmrc
    echo "http-proxy=http://$username:$password@$proxy" >> ~/.npmrc
    echo "http_proxy=http://$username:$password@$proxy" >> ~/.npmrc
    echo "https_proxy=http://$username:$password@$proxy" >> ~/.npmrc
    echo "https-proxy=http://$username:$password@$proxy" >> ~/.npmrc
    
    ######################
    # WGET SETTINGS
    # (Bonus Settings! Not required for npm to work, but needed for lots of other programs)
    ######################
    echo "https_proxy = http://$username:$password@$proxy/" > ~/.wgetrc
    echo "http_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc
    echo "ftp_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc
    echo "use_proxy = on" >> ~/.wgetrc
    
    ######################
    # CURL SETTINGS
    # (Bonus Settings! Not required for npm to work, but needed for lots of other programs)
    ######################
    echo "proxy=http://$username:$password@$proxy" > ~/.curlrc
    
  • 然后在粘贴的代码中编辑“用户名”、“密码”和“代理”字段

  • 打开一个新的终端

  • 通过运行
    npm config list
    cat~/.npmrc

  • 尝试使用安装模块

    • npm安装\uuuuu
      ,或
    • npm--没有ssl--安装不安全\u
      ,或
    • 通过使用
      npm——无ssl——不安全——代理来覆盖代理设置http://username:password@代理:8080安装
    • 如果希望模块在全球范围内可用,请添加选项
      -g
  • $npm配置集代理http://login:pass@主机:端口
    $npm配置集https代理http://login:pass@主机:端口
    
    虽然我用config设置了代理,但问题并没有解决,而是在 这一个对我有用:

    npm--https代理安装cordova插件

    npm—代理安装


    要设置http代理,请设置-g标志:

    sudo npm配置集代理http://proxy_host:port -g
    

    对于https代理,再次确保设置了-g标志:

    sudo npm配置集https代理http://proxy_host:port -g
    

    这在Windows中对我很有效:

    npm config set proxy http://domain%5Cuser:pass@host:port
    
    如果您不在任何域中,请使用:

    npm config set proxy http://user:pass@host:port
    
    如果您的密码包含特殊字符,如
    @
    等,请将其替换为URL编码值。例如
    ->
    %22
    ->
    ->
    %40
    ->
    %3A
    <代码>%5C
    用于字符
    \

    这对我很有用。 设置http和https代理

    • 配置集代理
    • npm配置集https代理

    我尝试了所有这些选项,但出于某种原因,我的代理没有任何选项。然后,出于绝望/绝望,我在Git Bash shell中随机尝试了
    curl
    ,结果成功了

    使用取消设置所有代理选项

    npm config rm proxy
    npm config rm https-proxy
    

    然后在我的Git Bash shell中运行
    npm安装
    ,效果非常好。我不知道它是如何为代理正确设置的,Windows
    cmd
    提示符也不正确,但它起作用了。

    当我在代理设置中没有http/http前缀时,即使代理主机和端口的值正确,npm也失败了。它只有在添加协议前缀后才起作用

    Windows系统上的

    尝试删除代理和注册表设置(如果已设置)并通过在命令行上设置环境变量

    SET HTTP_PROXY=http://username:password@domain:port
    SET HTTPS_PROXY=http://username:password@domain:port
    

    然后尝试运行npm安装。这样,您就不会在.npmrc中设置代理,但对于该会话,它将起作用。

    在cmd或GIT Bash或其他提示符下使用下面的命令

    $npm配置集代理“”

    $npm配置集https代理“”

    其中192.168.1.101为代理ip,4128为端口。根据您的代理集进行更改
    proxy=http://<username>:<pass>@<proxyhost>:<port>
    
    set http_proxy=http://domain%5Cuser:password%3F@myproxy:8080
    
    set http_proxy=http://domain%%5Cuser:password%%3F@myproxy:8080
    
    npm config set proxy http://proxy.company.com:8080
    npm config set https-proxy http://proxy.company.com:8080
    npm set strict-ssl=false
    
    proxy=http://<proxy-url>:<port>
    https-proxy=https://<proxy-url>:<port>
    registry=http://registry.npmjs.org/
    
    proxy=http://[IPADDRESS]:[PORTNUMBER]
    https-proxy=http://[IPADDRESS]:[PORTNUMBER]
    
    proxy=[IPADDRESS]:[PORTNUMBER]
    https-proxy=[IPADDRESS]:[PORTNUMBER]
    
    npm config list
    
    npm config set registry http://registry.npmjs.org/
    npm config set http-proxy http://username:password@ip:port
    npm config set https-proxy http://username:password@ip:port
    npm config set proxy http://username:password@ip:port
    npm set strict-ssl false
    
    npm config set proxy <http://...>:<port_number>
    npm config set registry http://registry.npmjs.org/
    
    npm config set registry http://registry.npmjs.org/
    npm config set proxy http://myusername:mypassword@proxy.us.somecompany:8080
    npm config set https-proxy http://myusername:mypassword@proxy.us.somecompany:8080
    npm config set strict-ssl false
    
    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
    
    npm config set proxy http://domain%5Cuser:password@proxy:port/
    npm config set https-proxy http://domain%5Cuser:password@proxy:port/
    
    npm config set strict-ssl false
    npm config set registry http://registry.npmjs.org/