Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors using JQuery with node.js

I have a fresh install of node.js running on Windows 7, and I am trying to run a very basic JQuery script, named a.js, which contains just:

require("jquery");
$().jquery;

Unfortunately, this will not run with JQuery, giving me a TypeError:

C:\Users\Ian>node a.js

C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10
    window.XMLHttpRequest.prototype.withCredentials = false;
                         ^
TypeError: Cannot read property 'prototype' of undefined
    at create (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:10:26)
    at C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9435:18
    at Object.<anonymous> (C:\Users\Ian\node_modules\jquery\lib\node-jquery.js:9437:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (C:\Users\Ian\a.js:1:63)

I have found a few bug reports on this error through Google, most of which suggest downgrading JQuery. However, when I do that, I just get a different error. The below is with JQuery 1.6.3:

C:\Users\Ian>node a.js

module.js:340
    throw err;
      ^
Error: Cannot find module 'location'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at create (C:\Users\Ian\node_modules\jquery\node-jquery.js:6:33)
    at C:\Users\Ian\node_modules\jquery\node-jquery.js:9065:18
    at Object.<anonymous> (C:\Users\Ian\node_modules\jquery\node-jquery.js:9067:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)

Can anyone suggest what may be wrong? I have tried various reinstallations of the software with no luck. I have tried both npm install -g and npm install for both the default version of jquery and also [email protected].

Edit: This question - as yet unanswered - seems related.

like image 439
Ina Avatar asked Oct 19 '12 17:10

Ina


2 Answers

If ur on node 0.10.x ... run sudo npm rebuild

https://github.com/coolaj86/node-jquery/issues/35

like image 88
Jonathan R. Avatar answered Sep 22 '22 03:09

Jonathan R.


In the git page for the jquery-nodejs project, says that does not works on Windows, so the problem is your OS. https://github.com/coolaj86/node-jquery

like image 27
jloria Avatar answered Sep 22 '22 03:09

jloria