Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Cornerstone3D tools does not build with vite #1071

Open
PintoGideon opened this issue Feb 9, 2024 · 11 comments
Open

[Bug] Cornerstone3D tools does not build with vite #1071

PintoGideon opened this issue Feb 9, 2024 · 11 comments

Comments

@PintoGideon
Copy link

PintoGideon commented Feb 9, 2024

Describe the Bug

I am currently using cornerstone3D in a react app. I get this error when running an npm run build during build:

Error: Could not load /home/gideonp/ChRIS_ui/node_modules/@icr/polyseg-wasm/dist/ICRPolySeg.wasm (imported by node_modules/@icr/polyseg-wasm/dist/index.js): "ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use `.wasm?init` or `.wasm?url`. See https://vitejs.dev/guide/features.html#webassembly for more details.
    at Object.load (file:///home/gideonp/ChRIS_ui/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:62695:19)
    at file:///home/gideonp/ChRIS_ui/node_modules/rollup/dist/es/shared/node-entry.js:18692:40
    at async PluginDriver.hookFirstAndGetPlugin (file:///home/gideonp/ChRIS_ui/node_modules/rollup/dist/es/shared/node-entry.js:18592:28)
    at async file:///home/gideonp/ChRIS_ui/node_modules/rollup/dist/es/shared/node-entry.js:17762:33
    at async Queue.work (file:///home/gideonp/ChRIS_ui/node_modules/rollup/dist/es/shared/node-entry.js:18802:32)

I tried instaling vite-plugin-wasm with no luck. Anyone else seeing this error ?

Steps to Reproduce

  1. Install Vite and the cornerstone3D tools
  2. npm run build

The current behavior

N/A

The expected behavior

N/A

OS

Linux

Node version

Nodejs 20.7

Browser

Chrome

jennydaman added a commit to jennydaman/ChRIS_ui that referenced this issue Feb 11, 2024
jennydaman added a commit to jennydaman/ChRIS_ui that referenced this issue Feb 11, 2024
@jennydaman
Copy link

I'm @PintoGideon's coworker.

For anyone else here looking for a workaround, see FNNDSC/ChRIS_ui#1060

UMD seems to be working but ESM (the default) does not. So create an alias in vite.config.ts to prefer the UMD build of @cornerstonejs/tools:

import { defineConfig } from "vite";

export default defineConfig({
  resolve: {
    alias: {
      "@cornerstonejs/tools": "@cornerstonejs/tools/dist/umd/index.js"
    },
  },
});

@jlopes90
Copy link
Contributor

jlopes90 commented Mar 1, 2024

#1067 (comment)

@sedghi sedghi reopened this Mar 8, 2024
@sedghi
Copy link
Member

sedghi commented Mar 8, 2024

seems like someone tried this and works for now

alias: {
'@cornerstonejs/tools': '@cornerstonejs/tools/dist/umd/index.js'
}
}`

@jlopes90
Copy link
Contributor

jlopes90 commented Mar 8, 2024

The umd works, but the problem is compressed and it doesn't seem to have a source map.

image

@sedghi
Copy link
Member

sedghi commented Mar 20, 2024

I know :( we will fix it in next version since it will be a breaking change

@fanhenghui
Copy link

seems like someone tried this and works for now

alias: { '@cornerstonejs/tools': '@cornerstonejs/tools/dist/umd/index.js' } }`

The code can be bundled, but it cannot run properly.

@desprit
Copy link

desprit commented Apr 3, 2024

While the "alias" workaround fixes some issues the current version still cannot run on vitest for example and gives the following error:

Module node_modules/@cornerstonejs/core/src/index.ts:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@cornerstonejs/core" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

Are there plans for a proper fix?

@Qwd2017
Copy link

Qwd2017 commented Apr 23, 2024

"node_modules@cornerstonejs\tools\src\workers\polySegConverters.js" is not packed to umd module and polyseg worker is not worked

@sedghi
Copy link
Member

sedghi commented Jun 17, 2024

Since there are many other people complaining about web workers and Vite as well, I'm adding this here.

vitejs/vite#8427

@vincent1996
Copy link

I modified the registerPolySegWorker.js code:
image
can be build,
But there are still errors when starting in Nginx
image
image

@sedghi
Copy link
Member

sedghi commented Jun 21, 2024

I'm working on cornerstone3D 2.x and have made progress in removing circular dependencies and publishing the types for the DICOM image loader. I'm trying to make it work with Vite, but there are numerous issues with Vite in dev mode, which are not directly related to Cornerstone. Multiple mentions of Vite problems with import.meta.url, web workers, and WebAssembly can be found on the Vite GitHub repository:

https://github.com/vitejs/vite/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+import.meta.url

I have started a template project for Vite, React, and cornerstone3D beta 2.x here. I appreciate your help in making it work.

https://github.com/cornerstonejs/vite-react-cornerstone3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants