Closed alexgleason closed 4 weeks ago
This package relies on native Node addons (https://docs.deno.com/runtime/fundamentals/node/#node-api-addons) and thus require node_modules
directory to be present. Additionally this library requires a lifecycle script to set up these bindings.
You can fix the problem by running with --node-modules-dir
flag or by putting { "nodeModulesDir": true }
in your config file. (Btw, in Deno 2 these will be --node-modules-dir=auto
and { "nodeModulesDir": "auto" }
). You might also need to specify --allow-scripts=npm:canvas
.
import { createCanvas } from 'npm:canvas';
$ deno run -A --node-modules-dir main.js
Warning rimraf@3.0.2 is deprecated: Rimraf versions prior to v4 are no longer supported
Warning npmlog@5.0.1 is deprecated: This package is no longer supported.
Warning inflight@1.0.6 is deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
Warning glob@7.2.3 is deprecated: Glob versions prior to v9 are no longer supported
Warning gauge@3.0.2 is deprecated: This package is no longer supported.
Warning are-we-there-yet@2.0.0 is deprecated: This package is no longer supported.
warning: Packages contained npm lifecycle scripts (preinstall/install/postinstall) that were not executed.
This may cause the packages to not work correctly. To run them, use the `--allow-scripts` flag with `deno cache`
(e.g. `deno cache --allow-scripts=pkg1,pkg2 <entrypoint>`):
npm:canvas@2.11.2
I'll try to improve the error message to provide a helpful message here.
Thank you very much @bartlomieju. I really don't want to have node_modules in my project, so I will have to fork one of these canvas repos. This canvas ecosystem needs to be pushed forward a bit.
@alexgleason just for info: hopefully in the coming months we will have OffscreenCanvas in Deno; it will not have 2DContext initially, but it is something we will add later on
Version: Deno 1.46.3
When trying to import node-canvas:
Why not use deno-canvas or skai_canvas instead? Because I am running into all kinds of issues: https://github.com/DjDeveloperr/deno-canvas/issues/40 https://github.com/DjDeveloperr/skia_canvas/issues/66 https://github.com/DjDeveloperr/skia_canvas/issues/68 https://github.com/DjDeveloperr/skia_canvas/issues/69
it's basically impossible to use a canvas library in Deno right now, and I thought with Node support node-canvas would be a last ditch effort, but something is blocking it from working here.