cornerstone3D icon indicating copy to clipboard operation
cornerstone3D copied to clipboard

[Bug] Wall of warnings when building app with vite

Open vnosikov opened this issue 1 year ago • 9 comments

Describe the Bug

Hi. I am currently in progress of moving from CRA to Vite. When I build an app I get a wall of warnings like these:

 WARN  Export "default" of module "node_modules/@cornerstonejs/core/dist/esm/cache/classes/ImageVolume.js" was reexported through module "node_modules/@cornerstonejs/core/dist/esm/cache/index.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
Either change the import in "node_modules/@cornerstonejs/core/dist/esm/index.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

 WARN  Export "default" of module "node_modules/@cornerstonejs/tools/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js" was reexported through module "node_modules/@cornerstonejs/tools/dist/esm/utilities/stackPrefetch/index.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.
Either change the import in "node_modules/@cornerstonejs/tools/dist/esm/utilities/index.js" to point directly to the exporting module or reconfigure "output.manualChunks" to ensure these modules end up in the same chunk.

and so on and on. Many such warnings.

I obviously cannot follow the first suggestion and change imports in your code. I tried to configure ouput.manualChunks, but had no success with removing these warnings. For example I tried:

build: {
      [...]
      rollupOptions: {
        output: {
          manualChunks: {
            cornerstone: [
              '@cornerstonejs/core/dist/esm/cache/classes/ImageVolume.js',
              '@cornerstonejs/core/dist/esm/cache/index.js',
              '@cornerstonejs/tools/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js',
              '@cornerstonejs/tools/dist/esm/utilities/stackPrefetch/index.js',
            ],
          },
        },
      },
    }
  },

or even

manualChunks: {
    cornerstone: [
       '@cornerstonejs/core',
       '@cornerstonejs/dicom-image-loader',
       '@cornerstonejs/streaming-image-volume-loader',
       '@cornerstonejs/tools',
    ],
},

Any advice? Did somebody encountered the same warnings? How dangerous is the "broken execution order" they tell about?

Steps to Reproduce

  1. Take the existing CRA project that uses cornerstone
  2. Remove CRA, configure vite
  3. npm run build - see the wall of warnings

The current behavior

Right now building a project that uses cornerstone with vite shows a lot of warnings

The expected behavior

I suppose either vite to be changed so that it could be built without tons of warnings, or some recommended configuration for vite.config.js should be provided.

OS

Ubuntu 22.04.3

Node version

20.10.0

Browser

Chrome 123.0.6312.58

vnosikov avatar Apr 25 '24 13:04 vnosikov

Hello, I am using Vite for packaging and have encountered the following issue:

Rollup failed to resolve import "a" from "E:/X-Revolution/Software/Frontend/node_modules/@icr/polyseg-wasm/dist/ICRPolySeg.wasm".

Have you ever encountered it?

IrvingLu avatar Apr 28 '24 02:04 IrvingLu

https://github.com/cornerstonejs/cornerstone3D/issues/1067

jlopes90 avatar Apr 28 '24 21:04 jlopes90

#1067 This is a solution, but when I tried to convert lablemap to contour, polyseg's webworker did not work and the thread was not visible in the browser because there was no worker folder under umd

IrvingLu avatar Apr 29 '24 01:04 IrvingLu

#1067 I read that issue and I had added this option. However it doesn't affect the wall of warnings I was telling about

vnosikov avatar Apr 30 '24 15:04 vnosikov

#1067 This is a solution, but when I tried to convert lablemap to contour, polyseg's webworker did not work and the thread was not visible in the browser because there was no worker folder under umd

Actually it is the answer. I just made a stupid typo previously. Thank you

vnosikov avatar May 03 '24 09:05 vnosikov

We will look into the vite problems soon

sedghi avatar May 04 '24 15:05 sedghi

I used this solution: "@ Cornerstonejs/tools": "@ Cornerstonejs/tools/dist/umd/index.js" But when I try to convert the labelmap to contour, the following error occurs: “ Cannot structure property 'geometryIds' of' a3 'as it is undefined“

IrvingLu avatar May 06 '24 03:05 IrvingLu

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

https://github.com/vitejs/vite/issues/8427

sedghi avatar Jun 17 '24 13:06 sedghi

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

sedghi avatar Jun 21 '24 14:06 sedghi