Hi Mat,

I am trying to use both ITK-JS and ITK-WASM. I have failed in both. please help me with following questions:

+I have followed this Node.js HelloWorld, and i failed with the error cannot find module itk/runPipelineNode? npx itk-wasm build worked like a charm
+++I have installed itk-wasm in my node.js project(npm install --save-dev itk-wasm)).
++I can see that inside package.json. I am not sure why node.js cannot find the itk/runPipelineNode module? is it part of node.js? I see in node_modules runPipelineNode.ts but i am not sure if there is a binary of that API?
++I have installed ITK/C++ on windows and it is inside c:\Program files\ITK folder! and this couple of years ago.
+++++what am i doing wrong?


Please try this Hello World example.
That’s an old link. I also ran into this issue last week :grinning:

1 Like

Hi Pranjal_Sahu,

I appreciate your answer about hello-world for itkwasi. I did try it but still i could not get it to work. it went well untill running following command:
itk-wasi -b .\web-wasi\ run .\hello.wasi.wasm

it seems not finding .wasi\itk-wasm-build-env. you can see it in the screenshot i have attached. docker image itkwasm/wasi is also download ed and i think it should be okay. the text [Hello WASM world!] did not appear in the terminal of vscode. I am not sure what would be wrong?! any ideas?
Node.js & Browser version did not work either. it does not print the [Hello WASM world!] in the termial.
there are two screen shots attached down below: 1. hello-world project in vscode 2. docker dashboard showing itkwasm/emscripten & itkwasm/wasi images which are download from docker hub. these are toolchains the WASM provided to build WASM & WASI executable to run with [itk-wasm] and [npx node] together.
I hope i did not get you lost with this long email.

HI Pranjal Sahu,

I appreciate you emailing me. I did try the examples in the link but all was failure. I did send you a comprehensive response on ITK discussion froum, i hope
you could take a look at it if you have time and give me some pointers how did you go about it and make it work.


Works for me on linux.
Can you please check if all the build files are present in the folder wasi-build ?

It works for me on linux.

@Albers_Steven , @Pranjal_Sahu ,

it is still not working for me. WSL Ubuntu 20.04.2 which is a linux windows subsystem builds the hello.wasi.wasm but when i run it, i get some issue inside itk-wasm. this is related to file access on file system. I get the error. ((import fs from ‘fs-extra’)) undefined syntax error. there is a gigling line under fs. when wasi version is created meaning a javascript wrapper around c++ is created which we call from linux. there must be an enviroment issue. I have installed node.js, nvm, WSL2 linux, my wsl2 linux is like a docker virtual machine which gives you opportunity to even have UI Graphics interface using windows X server to launch even android studio or anyother cartoons like xeyes on it, but that is besides the point, BUT I CANNOT RUN A SIMPLE WASI ON IT?

One more question can you tell me what are you environment setup ?

  1. docker installed running without using sudo.
    2.node.js installed ( I CAN RUN NODE.JS, I GUESS)
  2. I installed even nvm to nvm use any version of the node.js!
  3. installed npm
  4. try to install fs-extra and i see that in linux /usr/local/bin/node_mosules/…/ITK-WASM/…
    nothing helps. what is you environment in linux ?

may be that is my problem? i think that must be it.

still i get import fs from ‘fs-extra’

Maybe you can test on a linux machine.

I works for me on linux and MacOS.

So 99% that problem is your local environment setup.

1 Like

Hi Albers,

Thanks for the response. I finally managed to run the wasi version of hello world. I did reinstall my big sur OS which sort of make sure software work for macOS. then I installed nvm, node’s, docker desktop on my Mac. I did use nvm packet manager to keep track of my software inside the Mac.
through nvm use v17.1.0 I got to get the latest nodes and along with that I got nvm@8.12.2 which I guess solved my issue. then I build everything my docker built was-build and I could run hello world app and see the results on the nodes terminal.
now I am having issues with nodes version. I did built it correctly using its-wasm build. I did check my docker dashboard and its-wasm/emscripten was one of pulled images. I know the build Is correct checking because I have all the files in web-build.
I created index.mjs to run a module and this is inside the article now it complains hello.js has export default hello; at the end of the hello.js file. unexpected token ‘export’.
any idea why would a ESCMAScript get problematic when we runPiepelineNode(…).
this is on macOS! can you tell me what is in your environment.
by the way I am using the example in this url:
Hello WASM World! | itk-wasm which was suggested by pranks_sahu.
any idea or what might be wrong with index.mjs or my babel is old version or what is going on?


hi albers,

my typo in the explanation, replace nvm@8.12.2 with npm@8.12.2

Hi @sag ,

I confirmed that itk-wasm works with WSL2 on Windows, and this is best approach on Windows.

What are the exact steps, code, and error related to the fs-error?

nvm use v17.1.0

You want to use the even numbered versions of Node.js – these are the stable versions. The odd numbered versions are unstable. So, either v16 or v18.

I created index.mjs to run a module and this is inside the article now it complains hello.js has export default hello; at the end of the hello.js file. unexpected token ‘export’.

Can the exact contents of the file and error be provided?

PS: Note: The Docker Desktop WSL2 backend must be enabled.

Hi @matt.mccormick ,

I really appreciate your response. I tried to build and run ITK-WASM in windows but I failed. I did though succeed to build and run it in WSL2/ubuntu20.04 backend docker enabled environment. I reconfirm your post that WSL2 works for ITK-WASM.

Mat can you please help me with the ITK-WASM building an example where i pass one image into the wasm module and get out the processed image out of the wasm module using runPipelineNode in node.js environment. I am refering to the example MedianFilterTest pipeline example or Add noise to Image example of ITK.

Q. Tried to build and run MedianFilterTest example pipeline (ITK Examples) using ITK-WASM webassembly toolkit to compile it into javascript. I know that everything is working,

Here is my index.mjs code: Browed from mat ITK-WASM examples

`import path from “path”
import { IOTypes, readImageLocalFile, writeImageLocalFile, runPipelineNode, imageSharedBufferOrCopy } from “itk-wasm”
import { argv, argv0, stderr } from “process”

const testOutputFilePath = path.resolve(‘cthead1.png.out.json’);
const testInputFilePath = path.resolve(‘cthead1.png.json’);

console.log(“testInputFilePath”, testInputFilePath)
console.log(“testOutputFilePath”, testOutputFilePath)

console.log(“index.mjs: inside the module”);
console.log(“argv[0]”, process.argv[0]);
console.log(“argv[1]”, process.argv[1]);
console.log(“argv[2]”, process.argv[2]);
console.log(“argv[3]”, process.argv[3]);
console.log(“argv[4]”, process.argv[4]);

const ARGV1 = process.argv[1];
const ARGV2 = process.argv[2];
const ARGV3 = process.argv[3];
const ARGV4 = process.argv[4];

console.log(‘__dirname’, __dirname)

.then(function (image) {
const args = [‘cthead1.png.json’, ‘cthead1.png.out.json’, ‘4’]
const pipelinepath = path.resolve(“web-build”, ‘MedianFilterTest3’)
const desiredOutput = [{ path: args[1], IOTypes: IOTypes.Image }]

    const inputs = [{ path: args[0], type: IOTypes.Image, data: image }]
    console.log('Before runPipelineNode');
    return runPipelineNode(pipelinepath, args, desiredOutput, inputs)
}).then(function ({ stdout, stderr, outputs }) {
    console.log('After runPipelineNode')
    const useCompression = false;
    return writeImageLocalFile(useCompression, outputs[0].data, testOutputFilePath)
}).then(function () {
    console.log('DEBUG script runned - output image is written to the local disk.')

Following are the files and screen shots of the node.js application in vscode EDI:

  1. CMakeLists.txt file
    CMakeLists.txt (586 Bytes)

  2. cthead1.png.json file
    cthead1.png.json (10.3 KB)

  3. list of docker images download from docker hub screen shot illustrates all the necessary webassembly tools to build and run itk-wasm webassembly modules

  4. MedianFilterTest.cxx file
    MedianFilterTest.cxx (2.0 KB)

  5. After building the project MediaFilterTest3 under WSL2/ubuntu 20.0.4 , I launched it using this command line [npx node index.mjs cthead1.png.json cthead1_out.png.json 4} i get a crash with huge amount of javascript text dumped on the screen. there are two screen shots below illustrating this because is too large to show. It seems that it is complaining about PNGImageIOReadImage.js file. I searched the node_modules->itk-image-io package. I saw the file and it has umd and wasm version of it there too and it checks out.

This is the second part of the screen shot illustrating the last line of dumped javascript code

Mat can you help me to understand what is happening.
It seems to me that runPipelineNode(…) with parameters is the cause of this. I dont understand the sequence of the events: I have borrowed the index.mjs code from ITK-WASM examples provided by you. images are passed in and out of runPipelineNode API as <image.png.json>. I used online service to convert <image.png> to <image.png.json> please check out provided json images, do you think the json images are right? I saw somewhere there is an api in vtk to convert png files to json files? not sure please guide me with that.
is this [npx node index.mjs cthead1.png.json cthead1_out.png.json 4] the right way to call the webassembly module in node.js command line? i also pass args['cthead1.png.json', cthead1_out.png.json', '4'] inside index.mjs. Is this right way of running web assembly? when i dont include parameters in the command line i dont get them inside c++ code, so i figured this is correct. what is the sequence of events here. node calls index.mjs module and then entry point is c++ code which is compiled as web assembly in MedianFilterTest.wasm and then that calls MedianFilterTest.js ?
CAN YOU PRIVIDE ME WITH ALL THE JSON IMAGES AND index.mjs, and CMakeLists.txt, package.json, package-loc.json, so i know how to fix this?



Hi @sag ,

I did though succeed to build and run it in WSL2/ubuntu20.04 backend docker enabled environment. I reconfirm your post that WSL2 works for ITK-WASM.

Wonderful! :sparkler:

I am refering to the example MedianFilterTest pipeline example or Add noise to Image example of ITK.

Please see the new example / documentation that explains how to create and run a median filter pipeline in Node.js here:

@matt.mccormick , @dzenanz

Thank you i did


1 Like