1

I'm using the jsdom node.js module for an app that does some web scraping to get some data it needs. This works perfectly fine when I run locally.

When I push the application to cloudfoundry however, it crashes. The log is as follows:

====> /logs/stderr.log <====

/var/vcap/data/dea/apps/caretogethersandbox-0-8b20af9255bbf552d0f490cb60d0df55/app/node_modules/jsdom/lib/jsdom.js:171 features = JSON.parse(JSON.stringify(window.document.implementation._fea ^TypeError: Cannot read property 'implementation' of undefined

Is there something I'm missing here? I'm pretty stumped. I know the code I've written works fine, it just seems to be an issue between the module and cloudfoundry.

ZacAttack
  • 2,005
  • 5
  • 21
  • 34

2 Answers2

2

I was able to reproduce this problem pretty easily. It seems jsdom relies on a native compiled library called Contextify (https://github.com/brianmcd/contextify) and also has some bindings to Python from what I can gather. These are not supported by Cloud Foundry at present. There is a similar question on Github about this problem;

https://github.com/tmpvar/jsdom/issues/436

The last post at the time of writing this suggests the use of two 100% JS libraries called Domino and Zepto Node, they may well be worth checking out.

Dan Higham
  • 3,974
  • 16
  • 15
  • I am truly touched you took the time to reproduce my problem. This was the way to go. I also couldn't help but notice we work for the same company ;) – ZacAttack Aug 23 '12 at 17:39
  • Ah! nice, turns out that node.js package also has some crazy dependency on Python too! Which is actually why it doesn't work! – Dan Higham Aug 23 '12 at 18:14
  • Python dependency, WTF? If more of reason to ditch jsdom for cheerio. – jamjam Aug 23 '12 at 18:46
  • @jamjam I liked the cheerio module a lot, it was REALLY fast doing what I needed it to. Unfortunately, I couldn't get it to run on cloudfoundry either :( which is shame as I'm struggling with memory usage with the Domino Zepto modules – ZacAttack Aug 23 '12 at 22:41
1

With only what you posted to go by its pretty much impossible to give you a direct answer.

But I have a couple of suggestions.

  1. You have environmental variables that don't work the same in production as they do in development.

  2. jsdom relies on jquery that is normally loaded-in externally. Perhaps jquery is not loading properly.

Have you heard of cheerio. Its an alternative to jsdom that implements a subset of jquery and does not need to load jquery in externally. This makes much faster than jsdom.

You can watch this video created by the author for introduction to cheerio and learn more of its benefits.

Use the sample code on the cheerio github page and upload it your cloudfoundry account to see if everything works. Then you can make decision on weather to switch to cheerio.

jamjam
  • 3,171
  • 7
  • 34
  • 39
  • Yeah, sorry for the vague post, it's just that this is the only info I have to go on. I'm pretty sure posting the code will only distract from what's really the problem. I'll give this a try when I'm back at my main computer. – ZacAttack Aug 23 '12 at 02:38