konvajs / konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://konvajs.org/
Other
11.43k stars 918 forks source link

`canvas` dependency missing for node #1735

Closed CPatchane closed 6 months ago

CPatchane commented 6 months ago

Greetings 👋

I'd like to bring attention to an issue with the konva package. The Node.js version of konva utilizes the canvas dependency, but it is not listed in the konva package.json. This omission leads to problems when installing konva using a package manager like pnpm, which only exposes necessary dependencies (compared to yarn v1 or npm).

To reproduce this issue, install konva via pnpm and attempt to run Jest tests on files that use konva. You'll encounter the following error:

Cannot find module 'canvas' from 'node_modules/.pnpm/konva@9.3.6/node_modules/konva/lib/index-node.js'

This issue likely didn't exist when the Node.js version was separate, as in konva-node.

Proposed Solution 1: Include canvas as a dependency in konva's package.json. This should resolve the issue. Proposed Solution 2: Mention in the documentation to install canvas when using konva in a node environment.

lavrton commented 6 months ago

It is mentioned in the docs: https://github.com/konvajs/konva?tab=readme-ov-file#4-nodejs-env

Note: I don't add canvas into package.json because the major part of use cases is frontend only. So I don't want to pollute node_modules that is already too big everywhere.

CPatchane commented 6 months ago

Oops sorry I missed that info in the documentation, thanks for the link and that quick reply 🙌