jQuery installation issue with node-gyp rebuild

I’m facing difficulties while trying to install jQuery using npm and I keep encountering problems during the node-gyp rebuild step. The installation seems to fetch all dependencies successfully, but it fails during compilation.

Here’s the output I see in my terminal:

npm http GET https://registry.npmjs.org/jquery
npm http 304 https://registry.npmjs.org/jquery
npm http GET https://registry.npmjs.org/jsdom
npm http GET https://registry.npmjs.org/htmlparser/1.7.6
npm http GET https://registry.npmjs.org/xmlhttprequest
npm http GET https://registry.npmjs.org/location/0.0.1
npm http GET https://registry.npmjs.org/navigator
npm http 304 https://registry.npmjs.org/jsdom
npm http 304 https://registry.npmjs.org/xmlhttprequest
npm http 304 https://registry.npmjs.org/location/0.0.1
npm http 304 https://registry.npmjs.org/htmlparser/1.7.6
npm http 304 https://registry.npmjs.org/navigator
npm http GET https://registry.npmjs.org/cssom
npm http GET https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/request
npm http 304 https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings

> [email protected] install /root/node_modules/jquery/node_modules/jsdom/node_modules/contextify
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack     at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:68:16)
gyp ERR! stack     at Object.commands.forEach.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:56:37)
gyp ERR! stack     at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:185:20)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:105:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:534:7)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:91:17)
gyp ERR! stack     at maybeClose (child_process.js:634:16)
gyp ERR! stack     at Socket.ChildProcess.spawn.stdin (child_process.js:806:11)
gyp ERR! stack     at Socket.EventEmitter.emit (events.js:88:17)
gyp ERR! stack     at Socket._destroy.destroyed (net.js:356:10)
gyp ERR! System Linux 2.6.32-24-server
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/node_modules/jquery/node_modules/jsdom/node_modules/contextify
gyp ERR! node -v v0.9.1-pre
gyp ERR! node-gyp -v v0.6.5
gyp ERR! not ok 
npm WARN optional dep failed, continuing [email protected]

The error indicates something about pre-release versions and suggests using the --nodedir flag. Has anyone else faced this issue and found a fix?

Oh man, I remember this nightmare! Your issue is def the pre-release node version. Contextify needs to compile native code, but node-gyp won’t work with v0.9.1-pre at all. Easiest fix is grabbing node 0.8.15 or 0.10.0 - both work perfectly with jQuery. Don’t bother with the --nodedir workaround, it’s more trouble than it’s worth.

Had this exact problem last year on a legacy project. You’re using Node.js 0.9.1-pre, which is a pre-release version. node-gyp hates pre-release versions, and since contextify (jsdom dependency) needs native compilation, everything breaks. Two fixes: downgrade to stable 0.8.x or upgrade to a newer stable release. I switched to Node.js 0.8.14 and jQuery installed fine. The --nodedir flag is just a workaround - fixing the root cause with a stable Node version is way cleaner.

The contextify module is breaking because it needs native compilation through node-gyp, and that doesn’t work with pre-release Node versions like v0.9.1-pre. I hit this exact same issue on an older project. Just use Node Version Manager (nvm) to install a stable release - Node 0.10.x works great with that jQuery version. Don’t worry about the --nodedir error message, it’s misleading. The real problem is your Node version can’t compile native modules.