Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Errors using JQuery with node.js

Errors using JQuery with node.js

Problem

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. (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. (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. (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.

Problem courtesy of: Ina

Solution

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

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

Solution courtesy of: Jonathan R.

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Errors using JQuery with node.js

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×