npm install jsdom installed jsdom just fine on *nix
systems but we needed it working on both *nix and Windows. Installing it on Windows required a few
additional prerequisites. At the time several google searches unturned
good tips, but none of them worked fully for us. This is an attempt at a
complete picture of the issues and solutions.The issues discussed here may change as node progresses as it has
changed several times in the recent past.
The main issue at time of writing is that jsdom in turn requires a node module called contextify. Contextify requires a C++ addon, which must be built for the given platform. The way node builds these native addons is the build tool node-gyp.
- Node.js (at writing time using 0.6.19) and NPM (1.1.24). These are
packaged together when using the Windows installer
- Note: That my initial tests using node 0.8.0 and npm (1.1.32) also worked the same.
- Python: Node-gyp currently recommends 2.7.x
- Add python to your PATH
- Add a new environment variable
- This wasn’t listed in the node-gyp instructions but based on the output of the script it seemed necessary.
- Microsoft Visual C++. The express version works as a free alternative.
Once these prerequisites are installed jsdom is installed just like any other module via:
You should see output from node-gyp and then msbuild being invoked to compile the native module. In our experience msbuild would output a warning that was safe to ignore:
One of the other issues we had was finding a good, simple example to do a sanity check to make sure things were installed correctly. We found that the best example seemed to be the one from the site that loaded JQuery via a CDN and listed the links from Hacker News.