June 18, 2014

Installing Karma behind proxy


As part of working with AngularJS, I tried to install Karma test runner by using npm on one of our new Build Slaves. I got this error while executing the installation.
$ npm install karma

npm http 200 http://registry.npmjs.org/abbrev
> phantomjs@1.9.7-6 install /usr/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs
> node install.js
Downloading http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
Saving to /usr/lib/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/phantomjs/phantomjs-1.9.7-linux-x86_64.tar.bz2
Using proxy http://company-proxy.com:8080/
Receiving...
Error requesting archive.
Status: 403
Request options: {
  "protocol": "http:",
  "slashes": true,
  "auth": null,
  "host": "company-proxy.com:8080",
  "port": "8080",
  "hostname": "company-proxy.com",
  "hash": null,
  "search": null,
  "query": null,
  "pathname": "/",
  "path": "http://cdn.bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2",
  "href": "http://company-proxy.com:8080/",
  "headers": {
    "Host": "cdn.bitbucket.org",
    "User-Agent": "curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5"
  }
}
Response headers: {
  "cache-control": "no-cache",
  "pragma": "no-cache",
  "content-type": "text/html; charset=utf-8",
  "proxy-connection": "Keep-Alive",
  "connection": "Keep-Alive",
  "content-length": "606"
}
Make sure your network and proxy settings are correct.
npm ERR! phantomjs@1.9.7-6 install: `node install.js`
npm ERR! Exit status 1

Solution: Turns out that I need to set the proxy for npm:
$ npm config set proxy "http://company-proxy.com:8080"

Then I hit another problem, where the output has return code 407: Unauthorized; which means we need to add credential into the proxy config:
$ npm config set proxy "http://username:password@company-proxy.com:8080"
That's it. Installation successful!

Side notes:

Sometimes, you might need to set the registry and set https-proxy:
npm config set registry http://registry.npmjs.org/
npm config set https-proxy https://username:password@proxy.company.com:8080

References:

0 comments:

Post a Comment