8

Running node.js v0.10.2 and express v3.1.1 (latest at this time) and getting this error:

/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:10
window.XMLHttpRequest.prototype.withCredentials = false;
                     ^
TypeError: Cannot read property 'prototype' of undefined
  at create (/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:10:26)
  at /root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:9503:18
  at Object.<anonymous> (/root/dmr-addresses/node_modules/jquery/lib/node-jquery.js:9505: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> (/root/dmr-addresses/address/log.js:1:71)

line 1 of log.js is:

var $ = require('jquery');

I've tried running npm install jquery but it has not fixed the problem.

22
  • Is this on Windows or Linux? Do you have the log from the npm install? It looks like XMLHttpRequest is not a member of window. I am not sure jQuery adds that. Commented Apr 2, 2013 at 20:55
  • Linux, log: gist.github.com/thomasjmwb/5296136 Commented Apr 2, 2013 at 20:57
  • I was only asking because the npm install for jQuery is problematic on Windows. Are you sure window.XMLHttpRequest is a part of jQuery? I'm not extremely well versed, but I don't recall that. Commented Apr 2, 2013 at 21:00
  • I'm not sure, I started to get this error after upgrading to the most recent version of node though. I've also made sure try the answers to this question but have not had any luck yet.. stackoverflow.com/questions/12979531/… Commented Apr 2, 2013 at 21:08
  • 1
    @AmolMKulkarni I think you are correct, I cannot work on this at the moment but once I am able to I will follow your suggestion, thanks. Commented Apr 4, 2013 at 19:07

3 Answers 3

9

Check this:

Same error here... I don't know what I'm doing, but I changed the node-jquery.js fourth-fifth row's and it's start working :)

old:

if(window == null ) {
    window = require('jsdom').jsdom().createWindow();

new:

if(!window || !window.document) {
    window = require('jsdom').createWindow();
    window.document = require('jsdom').jsdom();
Sign up to request clarification or add additional context in comments.

Comments

1

You don't actually have a prototype object in Node server code, it's all stored in the much nicer __proto__ object and you should be using Object.create/defineProperty.

What exactly are you trying to do? Run an ajax query with Node? If so, you should be using Nodes http.request

An example could be:

require('request').post({
    "uri"     : "http://example.com/",
    "headers" : {
        'content-type': 'application/json'
    },
    "body"    : "hello=world"
},
function(e,r,b){
    // e = errors, r = response and b = returned body
    console.log(b,r.statusCode));
});

Comments

1

Looks like this is an issue with the jsdom module that node-jquery depends on. It appears that this is a known issue, and that it has been fixed, but not published to npm yet.

Check it out: https://github.com/coolaj86/node-jquery/issues/52

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.