About TypeError: needs a 'context' argument #417

fairy0815 opened this Issue Mar 9, 2012 · 12 comments

9 participants


I'm working on WIndows, and when I try to use jsdom like the following code, I got an error

    html: body,
    scripts: ['http://code.jquery.com/jquery-1.6.min.js']
  }, function(err, window){
    var $ = window.jQuery;

Error Return
global = vm.runInContext('this', sandbox);
TypeError: needs a 'context' argument.
at Object.getGlobal (C:\my_coding_space\fund\node_modules\jsdom\lib\jsdom\b
at Object.createWindow (C:\my_coding_space\fund\node_modules\jsdom\lib\jsdo
at Object.windowAugmentation (C:\my_coding_space\fund\node_modules\jsdom\li
at Object.parentWindow (C:\my_coding_space\fund\node_modules\jsdom\lib\jsdo
at Object. (C:\my_coding_space\fund\node_modules\jsdom\lib\jsdom
at C:\my_coding_space\fund\node_modules\jsdom\lib\jsdom.js:170:52
at Object.env (C:\my_coding_space\fund\node_modules\jsdom\lib\jsdom.js:262:
at Request._callback (C:\my_coding_space\fund\routes\index.js:27:13)
at Request.callback (C:\my_coding_space\fund\node_modules\request\main.js:1
at Request. (C:\my_coding_space\fund\node_modules\request\main.j


"name": "jsdom",
"version": "0.2.13"


what does err look like? what html are you passing?


I am seeing similar issues on Mac OS 10.6.8, node 0.6.12, jsdom 0.2.13.

If I try to run the tests I see lots of stack traces that look like this:

global = vm.runInContext('this', sandbox);
TypeError: needs a 'context' argument.
at Object.getGlobal (/Users/twl/work/js/node.js/jsdom/lib/jsdom/browser/index.js:26:21)
at Object.createWindow (/Users/twl/work/js/node.js/jsdom/lib/jsdom/browser/index.js:308:23)
at Object.windowAugmentation (/Users/twl/work/js/node.js/jsdom/lib/jsdom/browser/index.js:63:24)
at Object.parentWindow (/Users/twl/work/js/node.js/jsdom/lib/jsdom/browser/index.js:597:28)
at Object. (/Users/twl/work/js/node.js/jsdom/lib/jsdom.js:81:15)
at /Users/twl/work/js/node.js/jsdom/lib/jsdom.js:170:52
at [object Object]. (fs.js:115:5)
at [object Object].emit (events.js:64:17)
at afterRead (fs.js:1117:12)
at Object.wrapper as oncomplete


I traced my problem down to the absence of Contextify in the node path.


I was also getting this error running in windows.

These were the steps I took in order to fix it:
1. npm install -g node-gyp
2. Cloned the contextify repository git clone https://github.com/brianmcd/contextify.git
3. cd contextify
4. If you do not have a binding.gyp, but a bindings.gyp instead, run copy bindings.gyp binding.gyp (My pull request has been accepted, so this shouldn't be necessary, anymore.)
5. node-gyp clean
6. node-gyp configure
7. node-gyp build
8. Copy your entire contextify folder into the root node_modules folder for the nodejs app you're building.
9. cd my\node\project\ and then run this (not sure why this wasn't getting installed by npm already, but it might be because contextify had been giving errors when installing) npm install bindings


Thanks for the detailed instructions Rex. When I get to number 6, I get: "Error: 'gyp_addon' failed with exit code 1"... Do you have any ideas on what could be causing this? Thanks


heffe6 - make sure you're using Python v2.7.2. v3.x fails. Read the requirements for node-gyp here: https://github.com/TooTallNate/node-gyp


Looks like it worked. Thanks a lot ammonhaggerty!


I had this problem as well. on debian squeeze, node 0.6.12, and latest jsdom.

The solution of @RexMorgan did fix it for me. Thanks a lot!


I had the same problem and the solution of @RexMorgan did fix it for me on the server to.
But if I do the same on my dev-localhost I got this annoying TypeError: needs a 'context' argument - exception again.
So it seems that I am not able to have tne same node_modules-configuration on dev and prod :(

Does anyone has any Idea, whats going on here? Or does anone has any idea, how to handle two different node_modules if I want to use git pull/puhs for deployment?


This is a dupe of #456, and more evidence toward Contextify not being optional.

@domenic domenic closed this Oct 5, 2012
@vr2262 vr2262 added a commit to SEL-Columbia/dokomoforms that referenced this issue Mar 9, 2015
@vr2262 vr2262 Trying something I saw in tmpvar/jsdom#417 432628a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment