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

Support Deno #67

Open
alexgleason opened this issue Sep 29, 2024 · 0 comments · May be fixed by #68
Open

Support Deno #67

alexgleason opened this issue Sep 29, 2024 · 0 comments · May be fixed by #68
Assignees

Comments

@alexgleason
Copy link

With Deno v1.46.3 and captcha-canvas v3, I get this error:

➜  ~ deno
Deno 1.46.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { Captcha } from 'npm:captcha-canvas@3.2.3';
Uncaught Error: Cannot find module './v6'
Require stack:
- /home/alex/.cache/deno/npm/registry.npmjs.org/skia-canvas/1.0.2/lib/index.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/captcha-canvas/3.2.3/js-script/index.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/captcha-canvas/3.2.3/js-script/index.js
    at Function.Module._resolveFilename (node:module:608:15)
    at Function.Module._load (node:module:486:27)
    at Module.require (node:module:674:19)
    at require (node:module:801:16)
    at Object.<anonymous> (file:///home/alex/.cache/deno/npm/registry.npmjs.org/skia-canvas/1.0.2/lib/index.js:23:29)
    at Object.<anonymous> (file:///home/alex/.cache/deno/npm/registry.npmjs.org/skia-canvas/1.0.2/lib/index.js:1071:4)
    at Module._compile (node:module:736:34)
    at Object.Module._extensions..js (node:module:757:11)
    at Module.load (node:module:655:32)
    at Function.Module._load (node:module:523:13)
> 

I also tried v2:

➜  ~ deno
Deno 1.46.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> import { Captcha } from 'npm:captcha-canvas';
Uncaught Error: Cannot find module '../build/Release/canvas.node'
Require stack:
- /home/alex/.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/lib/bindings.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/lib/canvas.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/index.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/captcha-canvas/2.3.1/index.js
- /home/alex/.cache/deno/npm/registry.npmjs.org/captcha-canvas/2.3.1/index.js
    at Function.Module._resolveFilename (node:module:608:15)
    at Function.Module._load (node:module:486:27)
    at Module.require (node:module:674:19)
    at require (node:module:801:16)
    at Object.<anonymous> (file:///home/alex/.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/lib/bindings.js:3:18)
    at Object.<anonymous> (file:///home/alex/.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/lib/bindings.js:15:4)
    at Module._compile (node:module:736:34)
    at Object.Module._extensions..js (node:module:757:11)
    at Module.load (node:module:655:32)
    at Function.Module._load (node:module:523:13)

In both cases, the error seems to stem from the underlying canvas library.

Deno has two implementations of Skai, one based on wasm and another based on ffi.

Maybe there's an easy workaround that lets this work in Deno without having to swap out the canvas library. But if not, I think what makes the most sense is to create a v4 of this project that doesn't rely on any library at all, just a Canvas TypeScript interface. So that new Captcha(canvas: HTMLCanvasElement) would work, with the constructor taking the canvas element directly, or maybe even new Captcha(ctx: CanvasRenderingContext2D), which is even more flexible. The caller is then responsible for supplying the canvas implementation, and it would make the library work in all environments (even browser).

@Shashank3736 Shashank3736 self-assigned this Sep 30, 2024
@Shashank3736 Shashank3736 linked a pull request Sep 30, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants