【问题标题】:Proxy settings in npm-yeomannpm-yeoman 中的代理设置
【发布时间】:2014-01-17 05:47:18
【问题描述】:

我正在使用 yeoman 构建我的 Angular 应用程序。

我已将代理和注册表设置如下:

npm config set proxy http://proxy.tcs.com:8080

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

npm config set registry http://registry.npmjs.org/

即使在如上所述设置代理之后,在安装时

npm install grunt-ngmin,

我收到以下错误,

npm WARN package.json teamshareangular@0.0.0 No README.md file found!
npm http GET http://registry.npmjs.org/grunt-ngmin
npm http 407 http://registry.npmjs.org/grunt-ngmin
npm ERR! registry error parsing json
npm ERR! SyntaxError: Unexpected token <
npm ERR! <HEAD><TITLE>Proxy Authorization Required</TITLE></HEAD>
npm ERR! <BODY BGCOLOR="white" FGCOLOR="black"><H1>Proxy Authorization Required</H1><HR>
npm ERR! <FONT FACE="Helvetica,Arial"><B>
npm ERR! Description: Authorization is required for access to this proxy</B></FONT>
npm ERR! <HR>
npm ERR! <!-- default "Proxy Authorization Required" response (407) -->
npm ERR! </BODY>
npm ERR!
npm ERR!     at Object.parse (native)
npm ERR!     at RegClient.<anonymous> (C:\Users\Documents\tools\nodejs\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\request.js:235:23)
npm ERR!     at Request.self.callback (C:\Users\Documents\tools\nodejs\nodejs\node_modules\npm\node_modules\request\main.js:120:22)
npm ERR!     at Request.EventEmitter.emit (events.js:98:17)
npm ERR!     at Request.<anonymous> (C:\Users\Documents\tools\nodejs\nodejs\node_modules\npm\node_modules\request\main.js:648:16)
npm ERR!     at Request.EventEmitter.emit (events.js:117:20)
npm ERR!     at IncomingMessage.<anonymous> (C:\Users\Documents\tools\nodejs\nodejs\node_modules\npm\node_modules\request\main.js:610:14)
npm ERR!     at IncomingMessage.EventEmitter.emit (events.js:117:20)
npm ERR!     at _stream_readable.js:910:16
npm ERR!     at process._tickCallback (node.js:415:13)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Users\\\Documents\\tools\\nodejs\\nodejs\\\\node.exe" "C:\\Users\\\Documents\\tools\\nodejs\\nodejs\\node_modules\\npm\\bin\\npm-cli.j
"grunt-ngmin"
npm ERR! cwd C:\nodejs\Teamshare\Teamshareangular
npm ERR! node -v v0.10.7
npm ERR! npm -v 1.2.14
npm ERR! type unexpected_token
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\nodejs\Teamshare\Teamshareangular\npm-debug.log
npm ERR! not ok code 0

为此要做什么?

我应该在 npm 中进行一些其他设置吗?

请指教。

【问题讨论】:

  • 可能是您的代理不允许匿名连接,需要授权。
  • 如何克服?

标签: node.js proxy npm


【解决方案1】:

您的代理需要身份验证。如果您的控制中有代理,则创建一个用户并使用以下命令配置 npm 以使用您的凭据。 (注意用户名并在主机名之前传递)

$ npm config set proxy http://login:pass@host:port

$ npm config set https-proxy http://login:pass@host:port

【讨论】:

    【解决方案2】:

    出于各种原因,最明显的是安全性,您可能希望避免将代理凭据以明文形式放入 npm 配置中。

    但是,您可以安装一个本地转发代理来卸载代理身份验证。就我个人而言,我使用 squid(与 SquidMan 结合使用,一些同事使用 cntlm。Cntlm 有怪癖并且未维护,但 squid 对我来说效果很好。

    我在 localhost:4321 上运行 squid 并配置 npm 以连接到 http://localhost:4321。然后 Squid 使用存储的加密凭据对公司代理进行身份验证。

    【讨论】:

      猜你喜欢
      • 2014-12-15
      • 2019-04-08
      • 2016-04-15
      • 2017-01-13
      • 2014-11-26
      • 2016-12-29
      • 1970-01-01
      • 2014-08-19
      • 2023-03-05
      相关资源
      最近更新 更多