cornerstonejs / cornerstone3D

Cornerstone is a set of JavaScript libraries that can be used to build web-based medical imaging applications. It provides a framework to build radiology applications such as the OHIF Viewer.
https://cornerstonejs.org
MIT License
493 stars 256 forks source link

[Bug] server error: self is not defined using svelte kit and vite #681

Closed PintoGideon closed 1 year ago

PintoGideon commented 1 year ago

Describe the Bug

Hello there,

I am trying to use @cornerstone/core in svelte kit (installed using vite). I run into the issue pasted below.

Internal server error: self is not defined
      at Object.<anonymous> (/home/gideonp/svelte_chris_ui/node_modules/@cornerstonejs/core/dist/umd/index.js:2:9594)
      at Module._compile (node:internal/modules/cjs/loader:1275:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
      at Module.load (node:internal/modules/cjs/loader:1133:32)
      at Module._load (node:internal/modules/cjs/loader:972:12)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
      at ModuleJob.run (node:internal/modules/esm/module_job:193:25) (x2)
ReferenceError: self is not defined
    at Object.<anonymous> (/home/gideonp/svelte_chris_ui/node_modules/@cornerstonejs/core/dist/umd/index.js:2:9594)
    at Module._compile (node:

These are all the packages that I use to get a viewer working.

import * as cornerstoneTools from "@cornerstonejs/tools";
import { init as csRenderInit } from "@cornerstonejs/core";
import { RenderingEngine, type Types } from "@cornerstonejs/core";
import { ViewportType } from "@cornerstonejs/core/dist/esm/enums";
import dicomParser from "dicom-parser";
import cornerstoneDICOMImageLoader from "@cornerstonejs/dicom-image-loader";

Is there a solution for this ?

Steps to Reproduce

Install sveltekit with vite and use the cornerstone libraries in the project.

The current behavior

Seeing a bug 'self' is not defined.

The expected behavior

To work as it works in React.

OS

Ubuntu 22.04.2 LTS

Node version

19.8

Browser

Chrome: Version 103.0.5060.53 (Official Build) (64-bit)

PintoGideon commented 1 year ago

I got it to work using the browser variable exported by svelte kit. This is a client only library.