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

Error: Cannot find module 'canvas' #91

Open
tomerdo opened this issue Mar 7, 2020 · 3 comments
Open

Error: Cannot find module 'canvas' #91

tomerdo opened this issue Mar 7, 2020 · 3 comments

Comments

@tomerdo
Copy link

tomerdo commented Mar 7, 2020

Hi,
I am trying to use webppl-viz,
but it seems like that something wrong with canvas dependency.
I get the error: "Error: Cannot find module 'canvas'".

i use the viz as viz(thetaPosterior);
and run the program as webppl .\survey\survey-with-half.wppl --require webppl-viz

Regards,
Tomer

@null-a
Copy link
Member

null-a commented Mar 10, 2020

My guess is that something went wrong during the installation of webppl-viz. The install generates a lot of output, and I suspect there will have been an error in there somewhere.

In my experience webppl-viz is tricky to install. Here's a recipe that works for me at present. I'm using nvm to install Node, and already have Cairo installed as mentioned in the webppl-viz readme.

nvm install 9.0.0
npm -v #5.5.1
npm update -g npm
npm -v #5.10.0
npm explore npm -g -- npm install node-gyp@latest
mkdir ~/.webppl
cd ~/.webppl
npm install probmods/webppl-viz

Node v9 is rather old of course, but I expect it to be OK with WebPPL. It may also be possible to upgrade Node once webppl-viz is installed.

Hope that helps.

@vsenderov
Copy link

vsenderov commented Oct 14, 2022

This seems not to work for me unfortunately. It's very hard to install, but if you somehow manage, it still gives a runtime error

viktor@yggy:~/Dropbox/Work/phywppl/webppl-viz$ webppl test/render-file.wppl --require .
/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:18
  return g2D || (g2D = canvas.instance(1,1).getContext('2d'));
                                           ^

TypeError: Cannot read properties of null (reading 'getContext')
    at context (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:18:44)
    at textMark (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:169:11)
    at Object.itemBounds [as item] (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-scenegraph/src/util/bound.js:259:3)
    at /home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega/src/scene/Bounder.js:36:13
    at Array.forEach (<anonymous>)
    at Bounder.proto.evaluate (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega/src/scene/Bounder.js:35:15)
    at Model.prototype.evaluate (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-dataflow/src/Graph.js:329:16)
    at Builder.proto.evaluate (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega/src/scene/Builder.js:227:26)
    at Model.prototype.evaluate (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-dataflow/src/Graph.js:329:16)
    at Model.prototype.propagate (/home/viktor/Dropbox/Work/phywppl/webppl-viz/node_modules/vega-dataflow/src/Graph.js:161:22)

@WilliLam
Copy link

WilliLam commented Aug 3, 2023

I've managed to get it to work using a extended set of @null-a 's instructions

#install canvas dependencies
sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
nvm install 10.24.1  #@latest annotation requires NPM version >6.?.?
npm explore npm -g -- npm install node-gyp@latest
mkdir ~/.webppl
cd ~/.webppl
npm install [email protected]
npm install probmods/webppl-viz #I had to replace this with the .tar.gz file as installation hanged when using the npm/git link.

you can grab a tar.gz just by downloading the repo and then calling npm pack on it

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

No branches or pull requests

4 participants