kleisauke / wasm-vips

libvips for the browser and Node.js, compiled to WebAssembly with Emscripten.
https://kleisauke.github.io/wasm-vips/
MIT License
463 stars 25 forks source link

Unstable on Deno #46

Closed raunakdoesdev closed 1 year ago

raunakdoesdev commented 1 year ago

Running the await Vips() snippet form the README on Deno results in the following:

Deno 1.32.1
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 Vips from 'https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js';

undefined
> const vips = await Vips();
error: Uncaught (in worker "") TypeError: na is not a function
    at https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js:116:217
    at new Promise (<anonymous>)
    at e (https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js:116:191)
    at f (https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js:116:467)
    at dd (https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js:117:361)
    at https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js:118:327
kleisauke commented 1 year ago

This is due to missing dynamic modules support on Deno, which was fixed with commit 997031a94dcf5e2989c5456d664be78634a9a61e.

You can workaround this by disabling support for this (which implies that support for JPEG XL images is also disabled). For example:

import Vips from 'https://cdn.jsdelivr.net/npm/wasm-vips/lib/vips-es6.js';

const vips = await Vips({
  dynamicLibraries: []
});

// Load a formatted image from buffer
const buffer = await Deno.readFile('playground/src/images/banana.webp');
const thumbnail = vips.Image.thumbnailBuffer(buffer, 500, {
  option_string: '[n=-1]',
  height: 500
});

// Write the result to a blob
const outBuffer = thumbnail.writeToBuffer('.gif');
await Deno.writeFile('banana.gif', outBuffer);

// Exit the Deno runtime (i.e. a more "commandline" experience)
Deno.exit();
$ deno run --allow-net --allow-read --allow-write test.js
kleisauke commented 1 year ago

v0.0.5 now available, which includes support for dynamic modules on Deno.