Error: Cannot find module 'canvas'

I tried to run this code and got an error. Can you provide any tips to get this running?

var canvas = new (require("canvas"))(200, 200);
var context = canvas.getContext("2d");
require("canvas")
context.arc(100, 100, 100, 0, 2 * Math.PI, false);
context.fill();
canvas.toBuffer()

This code is taken directly from an example on the RunKit homepage: https://runkit.com/tolmasky/wpl-get-started-ported-to-javascript

Sorry about that, there was an issue with some packages when we added Node 8 support that caused them to be unavailable in all engines. I’ve fixed the issue for Canvas (https://runkit.com/me1000/593f0b55388cac001254c5ab) and it should work now!

- Randy

1 Like