Closed Francesco-Lanciana closed 1 week ago
The WASM version does not have Node.js support as Node.js has its own native build which is much better in every way.
Additionally, adding Node.js support to the WASM loader confuses the bundlers and requires special configuration when building a web application.
You don't have to manually copy anything. You just have to import the module from its default location.
You can eventually build your own WASM binaries that support Node.js by modifying meson.build
and removing this line:
'environments': ['web', 'webview', 'worker']
Thanks for the response. Good to know that the WASM version does not have Node.js support.
So just a few follow up questions:
npm install imagemagick.js --disable-tiff --...
? Will this rebuild imagemagick.js on my local device or is it pulling a prebuilt version? I'm mainly wondering if I have a cloud function with this dependency do I have to do anything to make it build correctly in a cloud environmentWhat happens if you simply follow the instruction in Installation and Importing on the homepage?
@mmomtchev that's what I'm trying to do but it doesn't work. The exact steps I take are as follows:
npm install magickwand.js
inside this folderimport ImageMagick from 'magickwand.js';
// ImageMagick will be either a native library
// (if called from a Node.js application)
// or a WASM bundle (when bundled by a web bundler)
const { Magick, MagickCore } = await ImageMagick;
node index.js
That gives me the error: Cannot use import statement outside a module
"type": "module",
to the package.json to resolve the above errornode index.js
Which now gives me the error The requested module 'magickwand.js' does not provide an export named 'default'
.
I might just be missing something really obvious regarding how I'm supposed to be running node whilst using import
instead of require
.
You installed magickwand.js
1.x and you used the installation/usage instructions for the latest 2.x beta.
Check https://www.npmjs.com/package/magickwand.js - both versions have their own installation/usage instructions.
2.x features an automatic resolver that selects either WASM or Node.js depending on the environment.
Ahh right, missed the version, thanks for the help.
One more related question though. I had to install libx11
and libXext
using brew in order to run for the code in my previous comment. I've read for operations where libx11 is not needed (e.g. conversions) it's possible to bypass installing it. I would like to run this program on a cloud function without the need to install libx11
and libXext
. Is this possible? If so I'd really appreciate if you could show me how I achieve that.
The next release should come with prebuilt binaries built without libX11
and libXext
. Currently, you have to rebuild from source.
I've attempted several ways to get this library to run but I can't even get a basic example working. I'm probably just not understanding a core concept and doing something silly but I'd really appreciate your help in resolving this.
My end goal is to execute the WASM binary in a Node.js process (on a cloud function) to convert HEIC images to JPG.
I've tried the following with the latest Node.js lts version (20.17.0) and the latest version (22.8.0). I am 2016 MacBook Pro (Intel Core i7) running OS 12.3.1.
Attempt 1: Following the instructions in the README
Step 1: Create a fresh directory and run
npm install magickwand.js
Step 2: Add"type": "module"
to the package.json Step 3: Create an index.js file with the following codeStep 4: Run
node index.js
Result: This gave me the following error:
The requested module 'magickwand.js' does not provide an export named 'default'
Attempt 2: Grabbing the WASM files from node_modules
Step 1: Create a fresh directory and run
npm install magickwand.js
Step 2: Add"type": "module"
to the package.json Step 3: Copymagickwand.js
andmagickwand.wasm
from "node_modules/magickwand.js/lib/binding/emscripten-wasm32" into the root of the directory Step 4: Create an index.js file with the following codeStep 5: Run
node index.js
Result: This gave me the following error:
TypeError: Magick.Image is not a constructor
Request
If possible I would love help with the following:
Also I'm pretty new to WASM so if what I'm trying to do makes no sense please let me know. My assumption is that a WASM binary should run anywhere (including in a cloud function if it's small enough) without the need for a complex build step, e.g. with Sharp I would need to create a docker container with the correct dependencies.
Thanks in advance for the help.