Unable to import vtk libraries.

Dear VTK Team,

We are trying to use vtk.js as suggested in the following link.

However, we are unable to import vtk libraries.

Could you please answer why is so?

Thank you so much for the help.

Best regards,
Sunita

You will have to provide more information of what you did that is not working.

Nowadays, it is better and simpler to import the ESM module (@kitware/vtk-js/… ) so you don’t have to play with transpiler rules of your build system.

Hi Sebastien,

We are beginners. We followed the tutorials as given. However, got following errors.

Could you please guide us explicitly on how to rectify it. We want to display vtp file of the tumor as 3D and we have generated vtp file from the medical images.

These are the steps we followed to do this.

Step 1: We have created a project folder and installed @kitware/vtk.js using npm. It created a node module folder.

Step 2: We created a HTML page in project folder and imported vtk.js script tag as given in the following example.

import ‘./node_modules/@kitware/vtk.js/Rendering/Core/RenderWindow’

When we executed the script we got following error.

If we add type = “module” in script tag we get following error.

Please help us in implementing vtk.js.

Your help will be highly appreciated.

Thank you so much.

Best regards,
Sunita

What you are doing is indeed not right. If you just want to write JavaScript in HTML directly without a build step you should look at that guide.

Otherwise you will have to learn how to develop with JavaScript and a bundler (webpack, vite, …). The VTK community can not teach you that part.

Hi Sebastien,

Thank you so much for your help. We didn’t know that vtk.js implementation requires webpack. Now we could figure it out. It’s working.

Here is the image we built using webpack.

Your guidance helped to built this.

Thanks again.

Best regards,
Sunita

1 Like

Is there any example how we can include vtk.js in an existing project(vite bundler is used).

If you use the ESM package, there is nothing to do.