Installing PhantomJS on NodeJS on Windows behind corporate proxy

posted by sacah on

Attempting to install phantomjs using npm, got an ETIMEOUT error, as you can see below

C:\Users\UserName\Downloads>npm install -g phantomjs
npm http GET https://registry.npmjs.org/phantomjs
npm http 304 https://registry.npmjs.org/phantomjs
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/adm-zip/0.2.1
npm http 304 https://registry.npmjs.org/adm-zip/0.2.1
npm http 304 https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/graceful-fs
C:\Users\UserName\AppData\Roaming\npm\phantomjs -> C:\Users\UserName\AppData\Roaming\npm\node_modules\phantomjs\bin\phantomjs

> phantomjs@1.9.0-3 install C:\Users\UserName\AppData\Roaming\npm\node_modules\phantomjs
> node install.js

Requesting C:\Users\UserName\AppData\Roaming\npm\node_modules\phantomjs\tmp\phantomjs-1.9.0-windows.zip

events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT
at errnoException (net.js:878:11)
at Object.afterConnect [as oncomplete] (net.js:869:19)
npm ERR! phantomjs@1.9.0-3 install: `node install.js`
npm ERR! `cmd "/c" "node install.js"` failed with 8
npm ERR!
npm ERR! Failed at the phantomjs@1.9.0-3 install script.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls phantomjs
npm ERR! There is likely additional logging output above.

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" "phantomjs"
npm ERR! cwd C:\Users\UserName\Downloads
npm ERR! node -v v0.10.3
npm ERR! npm -v 1.2.17
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\UserName\Downloads\npm-debug.log
npm ERR! not ok code 0

I configured npm to use my corporate proxy, and every other package has downloaded and installed successfully, I'm guessing the phantomjs installer is doing something different. Rather than figure out what it's doing different I just downloaded phantomjs-1.9.0-windows.zip to the package so it could install without downloading.

Navigate to
C:\Users\UserName\AppData\Roaming\npm-cache\phantomjs\1.9.0-3\package
Created dir ‘tmp’

Downloaded phantomjs-1.9.0-windows.zip from https://code.google.com/p/phantomjs/downloads/list

Copy phantomjs-1.9.0-windows.zip into the tmp dir, located at
C:\Users\UserName\AppData\Roaming\npm-cache\phantomjs\1.9.0-3\package\tmp
Now I used 7-zip to re-create the package.

Navigate to
C:\Users\UserName\AppData\Roaming\npm-cache\phantomjs\1.9.0-3
TAR the package dir, so you'll create package.tar

Then gzip package.tar, naming it package.tgz, this will overwrite the current file.

Then run the installer again and it will use the local phantomjs-1.9.0-windows.zip to complete the install.