PrismarineJS/prismarine-viewer

createCanvas is not a function #167

Permanently posted onGitHub

I'm trying to use prismarine-viewer.headless, specifically with this line: viewer(mc, { output: 'pov.png', frames: 1, width: 1920, height: 1080 }); However, upon executing that line, this error pops out:

/project/node_modules/prismarine-viewer/lib/headless.js:18
  const canvas = createCanvas(width, height)
                 ^

TypeError: createCanvas is not a function
    at module.exports (/project/node_modules/prismarine-viewer/lib/headless.js:18:18)
    at Client.<anonymous> (/project/bot.js:58:5)
    at Client.emit (events.js:315:20)
    at MessageCreateAction.handle (/project/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/project/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/project/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/project/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/project/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/project/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:315:20)

To add: prismarine-viewer is on 1.17.0, and mineflayer is on 3.2.0. Edit: Updated prismarine-viewer to 1.18.0 and mineflayer to 3.3.1; no difference.


you need a x server you can use xvfb-run -s "-ac -screen 0 1280x1024x24" node your_script.js

posted by rom1504 about 4 years ago

Done that, same error.

posted by Permanently about 4 years ago

what are you running ?

posted by rom1504 about 4 years ago

did you install node-canvas-webgl ?

posted by Karang about 4 years ago

what are you running ?

https://github.com/Permanently/Pharmer/tree/viewer

did you install node-canvas-webgl ?

Yep - no difference.

posted by Permanently about 4 years ago

Just tried the example/headless.js script with latest version, no issues. Can you please make sure that node-canvas-webgl is actually installed. You can also try to run the example to check if the issue is coming from your script.

posted by Karang about 4 years ago

what are you running ?

https://github.com/Permanently/Pharmer/tree/viewer

bot.js doesn't import prismarine-viewer

what are you running exactly?

posted by rom1504 about 4 years ago

what are you running ?

https://github.com/Permanently/Pharmer/tree/viewer

bot.js doesn't import prismarine-viewer

what are you running exactly?

Hadn't committed changes at that point. Try now.

Can you please make sure that node-canvas-webgl is actually installed. You can also try to run the example to check if the issue is coming from your script.

It is installed. Seems that the example script works fine, which begs the question on where the actual cause lies.

posted by Permanently about 4 years ago

I don't know why you get this createCanvas undefined error (thats usually a sign that it doesnt find the library). But anyway you have an other error: the headless backend is supporting mp4 videos only, your output file is png. If you want to take a single screenshot, you can look at this example: https://github.com/PrismarineJS/prismarine-viewer/blob/master/examples/exporter/screenshot.js

posted by Karang about 4 years ago

Ah right- looks like a lot more than the original line I had used; nevertheless, will give it a shot. Cheers!

posted by Permanently about 4 years ago

Fund this Issue

$0.00
Funded

Pull requests