Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test fails: "TypeError: jsdom.jsdom is not a function" in paper-node.js #62

Open
sergeiwallace opened this issue Sep 23, 2017 · 2 comments
Labels

Comments

@sergeiwallace
Copy link

sergeiwallace commented Sep 23, 2017

I have installed the dependencies and have gotten the webppl test to work, but unfortunately the webppl-agents test is failing for me (on Windows). When I run the test, I get the error:

C:\Users\username\.webppl\node_modules\webppl-agents>webppl --require webppl-dp --require . tests/tests.wppl
C:\Users\username\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:10835
        document = jsdom.jsdom('<html><body></body></html>'),
                         ^
TypeError: jsdom.jsdom is not a function
    at new <anonymous> (C:\Users\username\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:10835:19)
    at Object.<anonymous> (C:\Users\username\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:33:13)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\username\.webppl\node_modules\webppl-agents\src\visualization\gridworld.js:1:75)

Looking around on other threads, there appears to be a dependency issue with paper and jsdom, but I haven't been able to get a handle on it. Any thoughts?

@stuhlmueller
Copy link
Contributor

I reproduced this issue using the Docker node container:

root@057cd7d5ab79:~/.webppl/node_modules/webppl-agents# webppl --require webppl-dp --require . tests/tests.wppl
/root/.webppl/node_modules/paper/dist/paper-node.js:10835
	document = jsdom.jsdom('<html><body></body></html>'),
	                 ^

TypeError: jsdom.jsdom is not a function
    at new <anonymous> (/root/.webppl/node_modules/paper/dist/paper-node.js:10835:19)
    at Object.<anonymous> (/root/.webppl/node_modules/paper/dist/paper-node.js:33:13)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/root/.webppl/node_modules/webppl-agents/src/visualization/gridworld.js:1:75)

@Chanlaw
Copy link

Chanlaw commented Jul 3, 2019

I was able to fix this issue by editing paper-node.js. I replaced lines 10832-10839 with:

var jsdom = require('jsdom');
const { JSDOM } = jsdom;
domToHtml = require('jsdom/lib/jsdom/browser/domtohtml').domToHtml;
Canvas = require('canvas');
const { document } = (new JSDOM('')).window;
global.document = document;
window = document.defaultView;
navigator = window.navigator;
HTMLCanvasElement = Canvas;
Image = Canvas.Image;

And line 11471 with

canvas = new Canvas.Canvas(width, height);

Running webppl --require webppl-dp --require webppl-agents tests.wppl now yields

{
  utils: [ true, true ],
  makeGridWorldMDP: [ true ],
  makeBanditPOMDP: [ true ],
  makeGridWorldPOMDP: [ true ],
  makeMDPAgent: [ true ],
  makePOMDPAgent: [ true ],
  simulateMDP: [ true ],
  simulatePOMDP: [ true ],
  gridworldViz: [ true ],
  extend: [ true ],
  getMarginalObject: [ true ],
  makeBanditStartState: [ true ],
  makeBanditAgent: [ true ],
  inferBandit: [ true ],
  makeRestaurantSearchPOMDP: [ true ],
  getRestaurantHyperbolicInfer: [ true ]
}

as desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants