# ITK-JS && ITK-WASM

**URL:** <https://discourse.itk.org/t/itk-js-itk-wasm/5021>\
**Category:** Beginner Questions\
**Created:** [May 29, 2022, 1:20pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021 "2022-05-29T13:20:44Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [May 29, 2022, 1:20pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/1 "2022-05-29T13:20:45Z")

</div>

@matt.mccormick

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](https://insightsoftwareconsortium.github.io/itk-wasm/examples/hello_world_node.html), 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?

BR  
@sag

---

<div class="post-metadata">

**Author:** ![Pranjal\_Sahu](https://discourse.itk.org/user_avatar/discourse.itk.org/pranjal_sahu/32/2698_2.png) [@Pranjal\_Sahu](https://discourse.itk.org/u/Pranjal_Sahu)\
**Post date:** [June 2, 2022, 2:32pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/2 "2022-06-02T14:32:45Z")

</div>

Please try this [Hello World](https://wasm.itk.org/examples/hello_world.html) example.  
That’s an old link. I also ran into this issue last week 😀

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [June 7, 2022, 8:23am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/3 "2022-06-07T08:23:16Z")

</div>

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.  
BR  
sohrab

 ![hellow.world.node](https://discourse.itk.org/uploads/default/original/2X/0/07f53c8407196bf4678d846c55a8dd49823f2c1f.png)

 ![hello.wasi.wasm](https://discourse.itk.org/uploads/default/original/2X/6/66c9d9677d7c36d5b6dce6d2ea1b68f1a06e5c0f.png)  
 ![docker.itkwasi.wasi-itk.wasm](https://discourse.itk.org/uploads/default/original/2X/0/010f64cbd3e79cc90e9dce5b55ede29528b43ac8.png)

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [June 7, 2022, 3:01pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/4 "2022-06-07T15:01:25Z")

</div>

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.

thanks  
sohrab

---

<div class="post-metadata">

**Author:** ![Pranjal\_Sahu](https://discourse.itk.org/user_avatar/discourse.itk.org/pranjal_sahu/32/2698_2.png) [@Pranjal\_Sahu](https://discourse.itk.org/u/Pranjal_Sahu)\
**Post date:** [June 9, 2022, 7:00am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/5 "2022-06-09T07:00:27Z")

</div>

![Screen Shot 2022-06-09 at 2.59.29 AM](https://discourse.itk.org/uploads/default/original/2X/b/bde247c73ff0d4ddbd3aa318fa97561e4cf4e97d.jpeg)  
Works for me on linux.  
Can you please check if all the build files are present in the folder wasi-build ?

---

<div class="post-metadata">

**Author:** ![Albers\_Steven](https://discourse.itk.org/user_avatar/discourse.itk.org/albers_steven/32/2763_2.png) [@Albers\_Steven](https://discourse.itk.org/u/Albers_Steven)\
**Post date:** [June 17, 2022, 3:44am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/6 "2022-06-17T03:44:05Z")

</div>

It works for me on linux.

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [June 17, 2022, 5:18am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/7 "2022-06-17T05:18:42Z")

</div>

@Albers_Steven , @Pranjal_Sahu ,

Hi,  
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 ?

CAN YOU TRY TO RUN FROM INSIDE DOCKER LINUX MACHINE?  
may be that is my problem? i think that must be it.

@sag  
still i get import fs from ‘fs-extra’

---

<div class="post-metadata">

**Author:** ![Albers\_Steven](https://discourse.itk.org/user_avatar/discourse.itk.org/albers_steven/32/2763_2.png) [@Albers\_Steven](https://discourse.itk.org/u/Albers_Steven)\
**Post date:** [June 17, 2022, 6:24am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/8 "2022-06-17T06:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [June 19, 2022, 9:23pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/9 "2022-06-19T21:23:30Z")

</div>

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](https://wasm.itk.org/examples/hello_world.html) 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?

@sag

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [June 19, 2022, 9:25pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/10 "2022-06-19T21:25:27Z")

</div>

hi albers,

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

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [August 15, 2022, 9:03pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/11 "2022-08-15T21:03:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [August 15, 2022, 9:40pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/12 "2022-08-15T21:40:29Z")

</div>

> [@matt.mccormick](#):
>
> I confirmed that itk-wasm works with WSL2 on Windows, and this is best approach on Windows.

PS: _Note_: The [Docker Desktop WSL2 backend](https://docs.docker.com/desktop/windows/wsl/) must be enabled.

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [August 16, 2022, 5:00pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/13 "2022-08-16T17:00:30Z")

</div>

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]);  
console.log(“===========================================”);

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

console.log(‘\_\_dirname’, \_\_dirname)

readImageLocalFile(testInputFilePath)  
.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](https://discourse.itk.org/uploads/short-url/bTXb975ZXeUc8PVGplkRZ7wNRvk.txt) (586 Bytes)

2. cthead1.png.json file  
[cthead1.png.json](https://discourse.itk.org/uploads/short-url/6lRV0IJblT2fnOxu9kzJpNmRfjf.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](https://discourse.itk.org/uploads/short-url/rzRBfhm2HKSdIfIxLxIy9omioBu.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.

 ![npx-node-index.mjs-cthead1.png.json-cthead1_out.png.json-radius1part](https://discourse.itk.org/uploads/default/original/2X/f/fee34effe44f6cad092345687fedd36795dafa24.png)

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

 ![npx-node-index.mjs-cthead1.png.json-cthead1_out.png.json-radius-2part](https://discourse.itk.org/uploads/default/original/2X/5/5bf663fcdce9b647f1a3e03d84e33a12abf6de7a.png)

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 ?  
WHAT IS THE PROBLEM TO CRASH?  
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?  
IS IT BECAUSE I USE WSL2/UBUNTU20.04?  
CAN YOU TEST THIS UNDER LINUX?

WHAT IS WRONG HERE PLEASE ASSIST ME WITH THIS IF IT IS NOT TOO MUCH TROUBLE.

THANKS  
@sag

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [August 23, 2022, 12:13am UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/14 "2022-08-23T00:13:06Z")

</div>

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! 🎇

> 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:

> <https://github.com/InsightSoftwareConsortium/itk-wasm/pull/615>

---

<div class="post-metadata">

**Author:** ![sag](https://discourse.itk.org/user_avatar/discourse.itk.org/sag/32/2041_2.png) [@sag](https://discourse.itk.org/u/sag)\
**Post date:** [August 26, 2022, 2:01pm UTC](https://discourse.itk.org/t/itk-js-itk-wasm/5021/15 "2022-08-26T14:01:54Z")

</div>

@matt.mccormick , @dzenanz

Thank you i did

BR  
@sag
