【问题标题】:NodeJS NPM Proxy error when installing grunt安装 grunt 时出现 NodeJS NPM 代理错误
【发布时间】:2015-01-15 08:25:53
【问题描述】:

当我尝试通过npm 安装grunt 时,出现以下错误:

C:\Program Files\nodejs\node_modules\npm>npm install -g grunt
npm ERR! network connect ETIMEDOUT
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "grunt"
npm ERR! cwd C:\Program Files\nodejs\node_modules\npm
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! syscall connect
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Program Files\nodejs\node_modules\npm\npm-debug.log
npm ERR! not ok code 0

我正在使用企业代理配置,并且我认为我遇到此错误是因为它的配置。为了成功安装 grunt,我需要进行哪些更改?

【问题讨论】:

    标签: node.js proxy gruntjs npm


    【解决方案1】:

    您需要配置 npm 配置文件,这可以在终端中完成:

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

    您的错误日志建议查看“npm help config”,所以我认为问题来自那里。

    如果您想要更多解释的链接,请参阅this blog entry(还有很多)

    祝你好运!

    【讨论】:

      【解决方案2】:

      如果您在“windows”域中的代理后面工作,请将域名添加到代理 url:

      npm config set proxy http://domain%5Cuser:password@proxy.company.com:8080
      npm config set https-proxy http://domain%5Cuser:password@proxy.company.com:8080
      

      您需要将反斜杠编码为 http uri 字符串:%5C

      如果您的用户名或密码中有特殊字符,也需要对这些字符进行编码。请记住,这些关键信息以纯文本形式存储在 npm 配置文件 (%HOME%\.npmrc) 中。 也可能需要将 npm 注册表指向 http 源:

      npm config set registry "http://registry.npmjs.org"
      npm config set strict-ssl false
      

      【讨论】:

        【解决方案3】:

        此配置对我有用。您需要检查您的 http 和 https 端口(通常它们分别是 80 和 443),但在我的情况下,我同时使用端口 80。

        npm config set proxy http://user:password@proxy.url.com:80
        
        npm config set https-proxy http://user:password@proxy.url.com:80
        

        您可以通过get 命令检查您的代理设置

        npm config get proxy
        
        npm config get https-proxy
        

        【讨论】:

          【解决方案4】:

          我之前也遇到过同样的问题,因为我像这样错误地使用了代理配置:

          npm config set proxy http://localhost:8080/ npm config set https-proxy http://localhost:8080/ npm config set strict-ssl false

          这使得 npm 客户端尝试访问 localhost:8080 来拉取模块,而不是正确的 Internet 端点。

          所以经过几天的挫折后,我找到了这个链接 https://docs.npmjs.com/cli/config

          告诉你运行

           npm config edit
          

          打开了一个文件,在该文件中,我删除了上面添加的那三行,是的,一切正常。 ALH 希望对您有所帮助。

          【讨论】:

          • 就是这样!我跑了npm config edit,发现了一个奇怪的IP,然后我删除了它,现在问题消失了。
          【解决方案5】:

          请使用 npm 配置设置代理http://xx.aa.bb.cc:port 它对我有用 非常感谢!

          【讨论】:

            【解决方案6】:

            运行 >> npm 配置编辑

            在编辑器中打开配置文件后,删除以下行

            registry=http://registry.npmjs.org/

            https-proxy=http://host/:port

            严格-ssl=false

            【讨论】:

              【解决方案7】:

              以下选项使它对我有用:

              npm 配置设置注册表“http://registry.npmjs.org

              npm 配置设置代理http://user:password@proxy.url.com:proxy-port

              npm config set strict-ssl false

              npm install -g -d 哟

              【讨论】:

                【解决方案8】:

                你可以在cmd中运行这个

                npm config set <key> <value> [-g|--global]
                npm config get <key>
                npm config delete <key>
                npm config list
                npm config edit
                npm get <key>
                npm set <key> <value> [-g|--global]
                

                npmrc.txt 将运行,您可以更改链接和端口

                 proxy =http://proxy.company.com:8080
                
                 https-proxy = http://proxy.company.com:8080
                

                reference

                【讨论】:

                  【解决方案9】:

                  让 npm 在代理网络中正常工作的三件事。

                  这个设置 npm 注册表,默认可能需要 https。

                  npm 配置设置注册表“http://registry.npmjs.org/

                  其次是您系统中的两组代理。如果您的组织使用代理或您。

                  npm 配置设置代理“http://username:password@proxy-url:proxy-port

                  npm 配置设置 https-proxy "http://username:password@proxy-url:proxy-port"

                  【讨论】:

                    【解决方案10】:

                    由于.npmrc 文件中的配置设置而发生错误 目录C://Users/&lt;username&gt;/

                    在记事本中打开 .npmrc 文件并删除其中设置的代理。您只需要将 ms 构建版本和 ssl 设置为 false,如 所示。

                    这将解决问题。现在 npm install 可以正常工作了。

                    【讨论】:

                      【解决方案11】:

                      如果您感到沮丧,并且这些猴子业务都不适合您,只需下载并运行最新的 MSI。 https://nodejs.org/en/download/

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 2015-02-01
                        • 2016-10-13
                        • 2020-01-28
                        • 2013-02-19
                        • 2018-06-03
                        • 1970-01-01
                        • 2015-04-27
                        • 1970-01-01
                        相关资源
                        最近更新 更多