【问题标题】:Unable to npm install Angular-cli after proxy configuration代理配置后无法 npm install Angular-cli
【发布时间】:2018-04-12 06:18:45
【问题描述】:

我正在尝试使用 npm install 在 Windows 10 中下载 Angular。由于我在公司代理上,我将代理配置为 username:password@server:port

但是,我在运行时遇到了这个问题

npm ERR! code E407 npm ERR! 407 Proxy Authorization Required: @angular/cli@latest

调试日志如下:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   '--proxy',
1 verbose cli   'http://XXXXX',     //Removed my proxy details
1 verbose cli   '--without-ssl',
1 verbose cli   '--insecure',
1 verbose cli   '-g',
1 verbose cli   'install',
1 verbose cli   '@angular/cli' ]
2 info using npm@5.4.2
3 info using node@v8.8.1
4 verbose npm-session 40ab1dc3dabb6029
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 407 http://registry.npmjs.org/@angular%2fcli 109ms
8 silly fetchPackageMetaData error for @angular/cli@latest 407 Proxy Authorization Required: @angular/cli@latest
9 verbose stack Error: 407 Proxy Authorization Required: @angular/cli@latest
9 verbose stack     at fetch.then.res (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\lib\fetchers\registry\fetch.js:42:19)
9 verbose stack     at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
9 verbose stack     at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
9 verbose stack     at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
9 verbose stack     at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
9 verbose stack     at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
9 verbose stack     at Async._drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
9 verbose stack     at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
9 verbose stack     at Immediate.Async.drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
9 verbose stack     at runCallback (timers.js:785:20)
9 verbose stack     at tryOnImmediate (timers.js:747:5)
9 verbose stack     at processImmediate [as _immediateCallback] (timers.js:718:5)
10 verbose cwd C:\Users\XXXXX
11 verbose Windows_NT 10.0.14393
12 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "--proxy" "http://XXXXX" "--without-ssl" "--insecure" "-g" "install" "@angular/cli"
13 verbose node v8.8.1
14 verbose npm  v5.4.2
15 error code E407
16 error 407 Proxy Authorization Required: @angular/cli@latest
17 verbose exit [ 1, true ]

知道是什么导致了这个问题吗?谢谢!

【问题讨论】:

  • 使用这个solution。它对我有用。

标签: node.js angular proxy npm-install


【解决方案1】:

这个配置对我有用:

方法1(命令行):

npm config set proxy http://user:password@domain_proxy:port/
npm config set https-proxy http://user:password@domain_proxy:port

be careful the url should be encoded. for example this password 01xx!tr should be introduced as 01xx%21tr. use this site to encode your url https://www.url-encode-decode.com/

example:
user/password => user1/01xx!tr
domain:port of the proxy => mydomain.org:8000
=> in that case :

npm config set proxy http://user1:01xx%21tr@mydomain.org:8000/
npm config set https-proxy http://user1:01xx%21tr@mydomain.org:8000

method2(编辑节点配置文件):

the method 2 is easier because we will not be botherd with encoding the urls

1- edit node configuration file (in windows it's located in %USERPROFILE%\.npmrc, example C:\Users\Jack\.npmrc)

2- add these lines
proxy=http://user:password@domain_proxy:port/
https-proxy=https-proxy http://user:passwor`enter code here`d@domain_proxy:port

example :
if the :
user/password => user1/01xx!tr
domain:port of the proxy => mydomain.org:8000

=> the configuration file should be look like this:

proxy=http://user1:01xx!tr@mydomain.org:8000/
https-proxy=http://user1:01xx!tr@mydomain.org:8000

【讨论】:

    【解决方案2】:

    解决了。 在我花了一些时间处理代理问题后,我发现我的错误是设置了 3 个代理变量:proxyhttp-proxyhttps-proxy强>。

    (注意:我在 stackoverflow 的某个地方读到我应该设置 http-proxy 但这是错误的)

    删除 http-proxy 为我解决了这个问题。

    设置npm proxy和npm https_proxy是正确的,如下:

    npm config set proxy http://user:password@proxy.companyname.com:port/
    npm config set https-proxy http://user:password@proxy.companyname.com:port/
    

    【讨论】:

    • 谢谢,经过两天的尝试,你的答案终于奏效了。
    【解决方案3】:

    尝试将 npm 注册表的 URL 设置为 http 而不是 https。你可以看看这个answer

    【讨论】:

    • 你能把你改成http后显示的错误的日志文件放在这里吗?
    • [原因:getaddrinfo EAI_AGAIN .:80] 表示存在 DNS 解析问题。请检查您的公司代理配置的代理和端口。许多使用 8080 作为代理端口。
    • 已将端口更改为8080,我得到的错误与我之前的相同。谢谢
    • 基本上您需要检查为您的公司网络配置的代理端口。 8080 可能不是您公司代理的端口。无论如何,这是 npm 的 DNS 解析问题。
    【解决方案4】:

    如果您已经配置了 Proxy 并且仍然无法使用 npm 命令进行安装。您可以尝试以下命令。看来您需要清除一些东西 - 这将解决问题。

    npm cache verify
    

    【讨论】:

      【解决方案5】:

      这些步骤对我有用

      编辑.npmrc 文件 添加以下行

      proxy=http://username:password@proxyaddress:portno
      https-proxy=http://username:password@proxyaddress:portno
      

      【讨论】:

        【解决方案6】:

        对我有用的东西如下, 问题:在“C:\Users*user-name*.npmrc”中定义的注册表错误。需要更新 npm 配置注册表。

        第 1 步 解决方案:从“C:\Users*user-name*.npmrc”文件中删除注册表项。

        第 2 步 在第 1 步之后,我得到了以下错误

        npm install -g @angular/cli npm WARN 注册表https://registry.npmjs.org/ 的意外警告:杂项警告 SELF_SIGNED_CERT_IN_CHAIN:对https://registry.npmjs.org/@angular%2fcli 的请求失败,原因:证书链中的自签名证书 npm WARN 注册表使用来自https://registry.npmjs.org/ 的陈旧包数据,因为在重新验证期间出现请求错误。

        问题:npm 维护者在 2 月 27 日宣布 npm 的自签名证书不再存在: 一群用户在今天全天安装和发布软件包期间收到“SELFSIGNEDCERTINCHAIN”错误。 npm 不再支持其自签名证书。 但是,推荐的修复对我来说失败了。

        解决方案:打开命令提示符,然后运行以下命令。 本地化 设置 npm_config_strict-ssl=false npm install npm -g --ca=null npm --版本 ENDLOCAL

        第 3 步 现在 >npm install -g @angular/cli 运行一切正常。

        【讨论】:

          【解决方案7】:

          在办公室配置代理,

          npm config set proxy http://user:password@proxy.companyname.com:port/
          npm config set https-proxy http://user:password@proxy.companyname.com:port/
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-03-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2018-05-08
            • 2017-09-27
            • 2018-12-02
            • 2018-07-30
            相关资源
            最近更新 更多