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
- Node.js 0.6.12 is required, apparently 0.6.13 will make this easier
- NPM 1.1.8 is required – Node.js is bundled with 1.1.4 so you’ll need to run npm install npm
- Python 2.7 is required – And the python runtime needs to be on the PATH
- 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
I believe you’ll also need the node-gyp module installed globallyNode-gyp is included in NPM
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.
Tags: bug fixes, jQuery, jsdom, Node.js, NPM, YUI
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
Steve Workman said:
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
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 Function._load (module.js:279:25)
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 Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
**************************************************************************************************
Do you have any idea about this?
Any advice will be very appreciate.
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.
Steve Workman said:
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.
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
spawn python [ 'C:\\Users\\Axllow\\.node-gyp\.6.15\\tools\\gyp_addon',
'binding.gyp',
'-IC:\\Users\\Axllow\\node_modules\\jsdom\\node_modules\\contextify\\build\\co
nfig.gypi',
'-f',
'msvs',
'-G',
'msvs_version=2010' ]
File “C:\Users\Axllow\.node-gyp.6.15\tools\gyp_addon”, line 40
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?
Steve Workman said:
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
Bruno Cassol said:
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)
- have python 2.7+ installed (http://www.python.org/download/)
- put python in your PATH env variable (in my case it is C:\Python27)
- logoff/restart your windows
- download latest node (http://nodejs.org/#download)
- make sure you have latest npm installed: npm install -g npm
- npm install -g jsdom
- cross your fingers
have a good day
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*
Steve Workman said:
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.
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.
Steve Workman said:
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
korean_ck.you said:
very good post
thank you~!!!!!