## Installing JSDom on Windows

If you’ve ever wanted to scrape a web page and extract some information using Node.js, there’s a really useful module called JSDom that parses a document and gives you a DOM that you can then manipulate with YUI or jQuery.

This all works really well… on Linux and OS X. On Windows, Node.js can’t run pre-built native Node.js libraries, so it has to be build by the NPM build service. This is all documented on the JSDom github issue, but for brevity, this is what you have to do to make it work

1. Node.js 0.6.12 is required, apparently 0.6.13 will make this easier
2. NPM 1.1.8 is required – Node.js is bundled with 1.1.4 so you’ll need to run npm install npm
3. Python 2.7 is required – And the python runtime needs to be on the PATH
4. Microsoft Visual C++ 2010 is also required – I’ve got the whole Visual Studio installed on my machine, but I think you’ll be able to get away with the distributable package
5. I believe you’ll also need the node-gyp module installed globally Node-gyp is included in NPM
Update: Node.js 0.6.13 is now out with npm 1.1.9 and an updated node-gyp which will make this a lot easier. However, you’ll still need Python 2.7 and Visual C++ 2010
Update 2: Having the Visual C++ redist package isn’t enough, you have to have Visual Studio installed too. You can get the express edition for free from Microsoft here
Update 3: The express edition of Visual C++ 2010 doesn’t come with the latest SDKs so it won’t compile out of the box. You’ll need to run Windows Update and download a special set of compiler updates from Microsoft. Thanks to Pavel Kuchera for finding this one out (the hard way).

That’s a lot of dependencies, but it should all work. Once Python and C++ are installed,  the commands you’ll need to run are:

npm install -g npm
npm install -g node-gyp
npm install jsdom

And that’s it. If there are build errors, let me or the JSDom team know.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

### Steve Workman

Steve Workman is the UI Tech Lead for yell.com at hibu. He is also an organiser for London Web Standards is an occasional public speaker, talking about web performance and web standards

Tags: , , , , ,

1. Jango said:

Can’t get this to work because of contextify.
Trying to work this out, but FYI:
C:\Program Files\nodejs>npm install jsdom
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/htmlparser
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/htmlparser
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/contextify

> contextify@0.1.2 preinstall C:\Program Files\nodejs\node_modules\jsdom\node_mo
dules\contextify
> node-waf clean || (exit 0); node-waf configure build

node-waf was unexpected at this time.
npm ERR! error installing contextify@0.1.2
npm ERR! error installing jsdom@0.2.13
npm ERR! error rolling back jsdom@0.2.13 Error: UNKNOWN, unknown error ‘C:\Progr
am Files\nodejs\node_modules\jsdom\node_modules\___htmlparser.npm\package’

npm ERR! contextify@0.1.2 preinstall: node-waf clean || (exit 0); node-waf conf
igure build
npm ERR! cmd “/c” “node-waf clean || (exit 0); node-waf configure build” faile
d with 1
npm ERR!
npm ERR! Failed at the contextify@0.1.2 preinstall script.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf clean || (exit 0); node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls contextify
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Windows_NT 5.1.2600
npm ERR! command “C:\\Program Files\\nodejs\\\\node.exe” “C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js” “install” “jsdom”
npm ERR! cwd C:\Program Files\nodejs
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! code ELIFECYCLE
npm ERR! message contextify@0.1.2 preinstall: node-waf clean || (exit 0); node-
waf configure build
npm ERR! message cmd “/c” “node-waf clean || (exit 0); node-waf configure build
“ failed with 1
npm ERR! errno {}

npm ERR! Error: ENOENT, no such file or directory ‘C:\Program Files\nodejs\node_
modules\jsdom\node_modules\___request.npm\package\tests\ssl\ca\ca.crl’
npm ERR! You may report this log at:
npm ERR!
npm ERR! or email it to:
npm ERR!
npm ERR!
npm ERR! System Windows_NT 5.1.2600
npm ERR! command “C:\\Program Files\\nodejs\\\\node.exe” “C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js” “install” “jsdom”
npm ERR! cwd C:\Program Files\nodejs
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! path C:\Program Files\nodejs\node_modules\jsdom\node_modules\___request
.npm\package\tests\ssl\ca\ca.crl
npm ERR! code ENOENT
npm ERR! message ENOENT, no such file or directory ‘C:\Program Files\nodejs\node
_modules\jsdom\node_modules\___request.npm\package\tests\ssl\ca\ca.crl’
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Program Files\nodejs\npm-debug.log
npm not ok

2. Hi Jango,

Try installing node-gyp as well and let me know if that helps. To get it, do “npm install -g node-gyp”. You also have to have some form of the VS2010 C++ builder installed, the link is in the post.

Steve

3. Kurt said:

Hi Steve,

I have JSDom installed in Windows 7 without any error. However, when executing a statement as :
var jsdom = require(‘jsdom’);

I get the following error message:

**************************************************************************************************

C:\Users\Kurt_Sally\Desktop\JavaScript>node node_basic_http_hello_world.js

node.js:201
throw e; // process.nextTick error, or ‘error’ event on first tick
^
Error: Cannot find module ‘C:Program Files
odejs
ode_modulesjsdomlibjsdom’
at Function._resolveFilename (module.js:332:11)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (C:\Users\Kurt_Sally\Desktop\JavaScript\node_basic_htt
p_hello_world.js:6:13)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Array.0 (module.js:479:10)

**************************************************************************************************

Any advice will be very appreciate.

4. Hawkeye Parker said:

Thanks for all your work and help on this, Steve!

I had similar problems to Jango (above). Turned out I had Python 3.2 installed. From node-gyp README: “v3.x.x not yet supported”. Using Python 2.7 worked.

5. From the stack trace, it looks like JSDom didn’t install correctly after all. Try installing it into an empty node project and paste the stack trace here and I’ll see if there’s anything wrong with it.

6. Axllow said:

Hi, a have Windows 7 x64, Python x64 2.7, node 0.6.15, npm 1.1.9, lastest Visual C++
and get this error

C:\Users\Axllow>npm install jsdom
npm http GET https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/htmlparser
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/htmlparser
npm http 304 https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

> contextify@0.1.2 install C:\Users\Axllow\node_modules\jsdom\node_modules\conte
xtify
> node-gyp rebuild

C:\Users\Axllow\node_modules\jsdom\node_modules\contextify>node “C:\Program File
s (x86)\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\n
ode-gyp.js” rebuild
info it worked if it ends with ok
‘binding.gyp’,
‘-IC:\\Users\\Axllow\\node_modules\\jsdom\\node_modules\\contextify\\build\\co
nfig.gypi’,
‘-f’,
‘msvs’,
‘-G’,
‘msvs_version=2010′ ]
print ‘Error running GYP’
^
SyntaxError: invalid syntax
ERR! Error: gyp_addon failed with exit code: 1
at Array.0 (C:\Program Files (x86)\npm\node_modules\npm\node_modules\node-gy
p\lib\configure.js:193:18)
at EventEmitter._tickCallback (node.js:192:40)
ERR! not ok
npm WARN optional dependency failed, continuing contextify@0.1.2
jsdom@0.2.14 ./node_modules/jsdom
??? cssom@0.2.3
??? request@2.9.201
??? htmlparser@1.7.6

Can you help me?

7. Try updating node-gyp:

Npm install -g node-gyp

Everything else seems to be in order. If that still gives you problems try posting your query on the GitHub issues list

8. Thanks for the post!

I got it working after doing many things and I’m not sure what solved my problems but here is what I did:

– have visual studio installed (express edition is free: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express)
– put python in your PATH env variable (in my case it is C:\Python27)
– make sure you have latest npm installed: npm install -g npm
– npm install -g jsdom

have a good day

9. Jake said:

I’ve followed your instructions to a “T”, and have had zero luck.

* Latest Node installed
* VS Studio C++ 2010 + Win 7 SDK / .NET 4.0 installed
* Python 2.7 installed, path setup correctly (CLI works)
* latest node-gyp, npm installed
* Restarted about 15 times today, no joke!

When I try to install jsdom, npm install -g jsdom, I get:

LINK: fatal error LNK1181: cannot open input file ‘kernel32.lib’ [c:\path\to\nodejs\build\contextify.vcxproj

I’ve spent 4 hours now trying to get JSDOM to work on Windows. I’m about to give up….. absolutely astonishing how many programming languages, tools/downloads, CLI commands etc. are needed to get this to work. I thought the whole purpose of node was to consolidate to ONE programming language? *bang head*

10. Are you using on Win7 x64? Are you using x64 Node? If not, that might be that. Alternatively, if you’re on Win7 32-bit, you’ll need to be using the 32-bit Node binary.

Alternatively, the only other info about that error message is about Visual Studio not working right. Take a look at this post and let me know if that helps: .

If it still doesn’t work, put the whole console log in a gist and I’ll take a look.

11. Pavel Ku?era said:

Hi, I’m experiencing problem with installing jsdom, now it’s like five hours of useless attemts. I would appreciate any help.

Environment:
Win 7×64
Node v0.8.1 x64
Newest npm – npm install -g npm
Visual C++ 2010 Free
Python 2.7

When I run ‘npm install jsdom’, all I get is https://gist.github.com/e6e89f1dd7c6a06d997b Seems like my crossed fingers don’t help it.
When I try to install only Contextify, I get https://gist.github.com/81d62825010a6285e4a8

It’s driving me crazy, I tried everything what crossed my mind, but it seems like that is not enough and got the same output all along.

12. Hi Pavel,

You’re not the first person who has come across this problem, so I’ve raised a query with the Contextify guys to see if there’s something that I’ve got installed that you don’t that they know of. You can track the issue here: https://github.com/brianmcd/contextify/issues/39

I’ll update the post when we get some resolution.

Cheers,
Steve

13. JeffF said:

Thanks for all of your work supporting JSDom on Windows!

However, it now being June of 2013, MS has replaced all of the links pointing to Visual Studio 2010 with Visual Studio 2012. So as I followed your instructions I had to install VS Express 2012.

When I run npm install -g jsdom I receive the following error message:
“MSBUILD : error MSB3411: Could not load the Visual C++ component “VCBuild.exe”.
If the component is not installed, either 1) install the Microsoft Windows SDK
for Windows Server 2008 and .NET Framework 3.5, or 2) install Microsoft Visual
Studio 2008. [C:\Users\jeff.furgal\AppData\Roaming\npm\node_modules\jsdom\nod
e_modules\contextify\build\binding.sln]

gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe failed with exit code: 1″
Etc., etc.

Has anyone been able to build JSDom with an SDK and tools newer than VS 2010?

14. Thanks very much for the link and the advice. I’m downloading the ISO now and I will give it a try as soon as I get some free time to roll everything back to 2010 versions.

15. You can have multiple versions of Visual Studio installed side-by-side – if you want to use a particular version’s command set, run npm from the Visual Studio 20XX command prompt instead of the regular cmd or git bash.

Let me know if it works!

16. Why is so much required to install JSDOM?

17. The issue is the Contextify library to allow for running JavaScript inside a browser context, with JSDOM running on the command line.
The issue is that this requires a lot of C++ magic, and on Windows, the de-facto compiler is Visual Studio. Python is also needed for running the scripts outside of the node environment.

18. Martijn said:

Instead of jumping through 213762 different hoops to get one plugin installed, jsdom could just simply include binaries for whatever it needs to compile. Problem solved.

19. Martijn said:

Also jsdom needs to get with the program and support Python 3. It’s been out for a while, and it doesn’t make sense to install two of them (unpredictable), neither does it make sense to only install the older one. Also users will be more prone to having the latest one anyway, so you might as well support that one.

20. For what it’s worth I have 64 bit python, 64 bit windows, but I still could only get this to work with a 32 bit node install. I was stuck on the ‘kernel32.lib’ issue until I switched node versions. No clue why node needed to be 32, but it did the trick.

Anyway awesome information thanks!

1. […] Installing JSDom on Windows | Steve Workman – If you’ve ever wanted to scrape a web page and extract some information using Node.js, there’s a really useful module called JSDom that parses a document and… […]

2. […] Installing JSDom on Windows | Steve Workman – If you’ve ever wanted to scrape a web page and extract some information using Node.js, there’s a really useful module called JSDom that parses a document and …… […]