thx / resvg-js

A high-performance SVG renderer and toolkit, powered by Rust based resvg and napi-rs.
https://resvg-js.vercel.app/
Mozilla Public License 2.0
1.57k stars 57 forks source link

Error using resvg-js in Supabase edge functions #341

Closed AndrewAskins closed 5 months ago

AndrewAskins commented 5 months ago

I'm trying to use resvg-js in a Supabase edge function. Supabase edge functions run Deno with some limitations.

I am including resvg-js the way that is suggested in the Deno example: import { Resvg } from 'npm:@resvg/resvg-js'

But I am getting the following error: runtime has escaped from the event loop unexpectedly: event loop error: Error: Unimplemented at Module._extensions..node (node:module:780:9) at Module.load (node:module:656:32) at Module._load (node:module:537:12) at Module.require (node:module:675:19) at require (node:module:791:16) at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@resvg/resvg-js/2.6.2/js-binding.js:1:4243) at Object.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@resvg/resvg-js/2.6.2/js-binding.js:3:4) at Module._compile (node:module:731:34) at Module._extensions..js (node:module:745:10) at Module.load (node:module:656:32) Error in worker connection: error writing a body to connection failed to send request to user worker: request has been cancelled by supervisor user worker failed to respond: request has been cancelled by supervisor WorkerRequestCancelled: request has been cancelled by supervisor at async Promise.allSettled (index 1) at async UserWorker.fetch (ext:sb_user_workers/user_workers.js:70:21) at async Object.handler (file:///home/deno/main/index.ts:165:14) at async handleHttp (ext:sb_core_main_js/js/http.js:112:15) { name: "WorkerRequestCancelled" }

Is this due to the limitations of the Supabase Deno environment or is this possibly an issue with how I am using resvg-js? Thanks for any help!

AndrewAskins commented 5 months ago

I was able to get it to work by including it like so:

import { Resvg, initWasm } from 'npm:@resvg/resvg-wasm'

and initializing it using:

await initWasm(fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm'))

And then following the node example from there.