Node.js jsdom error

I am trying to get jsdom to work :)

Here is the code:

var jsdom = require("jsdom"); var request = require("request"); var fs = require('fs'); var jquery = fs.readFileSync("./jquery-1.7.2.js", 'utf-8'); request({ uri:'http://nodejs.org/dist/' }, function (error, response, body) { if (error && response.statusCode !== 200) { console.log('HTTP request error... '+error); } jsdom.env({ html: body, scripts: [ jquery ], done: function(errors, window) { console.log('done'); } }); }); 

And here is the error:

 jsdom.js:171 features = JSON.parse(JSON.stringify(window.document.implementation._fea ^ TypeError: Cannot read property 'implementation' of undefined 

I checked if the page is selected, and if the jquery lib is parsed, they are.

We could look at the jsdom.js implementation:

 [snip] exports.env = exports.jsdom.env = function() { [snip] window = exports.html(html, null, options).createWindow(), features = JSON.parse(JSON.stringify(window.document.implementation._features)), docsLoaded = 0, [snip] 

It seems that .createWindow () failed ...

And I run it on Cloud9 .

Any help is appreciated.

+7
source share
3 answers

I found the answer to the question.

A piece of it can be found at http://support.cloud9ide.com/entries/21243717-accessing-your-private-running-project-via-javascript-or-curl .

So, in order for jsdom to work on cloud9, you need to use an older version (for example, 0.2.1) and run the script with the old version of node (for example, 0.4, which is supported in cloud9).

0
source

As reported at https://github.com/tmpvar/jsdom/issues/436 , this may be due to the fact that the context is not set. In theory, jsdom has a pad that allows it to work without context, so it is listed as an optional rather than a required module, but this pad seems broken (see https://github.com/tmpvar/jsdom/issues/456 ).

So, right now you need to set the context to use the latest jsdom. There are several reasons that may be a problem, depending on your OS and environment. Run npm install contextify and then open this problem.

What you need to do, depending on what your root problem is: - Make sure you have Python 2.7 or higher installed and optimally installed 2.7.3. Also check it, which starts when python -version is entered and that your PYTHONPATH is correct. - sudo npm install contextify - npm cache clean; npm install contextify --force

+7
source

Try updating jsdom. I had the same error with the old version of jsdom (0.3.x). Then I uninstalled it and installed the current version ( jsdom@0.6.5 ), and now it works.

0
source

All Articles