Viewers icon indicating copy to clipboard operation
Viewers copied to clipboard

[Bug] TS2307: Cannot find module @ohif/core or its corresponding type declarations

Open salkz opened this issue 11 months ago • 3 comments

Describe the Bug

Popular code editors like Visual Studio Code and WebStorm show TS2307 error for imported @ohif/* modules after following the instructions at https://docs.ohif.org/development/ohif-cli to create a new mode.

image image

Steps to Reproduce

Clone, install and create a test-mode:

mkdir -p ohif
mkdir -p ohif-modes

gh repo clone OHIF/Viewers ohif

yarn --cwd ohif config set workspaces-experimental true
yarn --cwd ohif install

# create `test-mode` into `ohif-modes`
yarn --cwd ohif run cli create-mode
yarn --cwd ohif run cli link-mode ../ohif-modes/test-mode

Now open up ohif-modes/test-mode/src/index.tsx and you should see the imports erroring.

The current behavior

Code editors show errors related to importing @ohif modules in modes (and extensions) created with cli.

The expected behavior

Code editors will not show errors related to importing @ohif modules in modes (and extensions) created with cli.

OS

macOS 14.2 (23C64)

Node version

v18.19.0

Browser

not related to a browser

salkz avatar Mar 07 '24 13:03 salkz

I can't reproduce this, I tried the steps required to create an link mode and worked fine. myabe don't give relative path to the mode for linking?

sedghi avatar Mar 15 '24 14:03 sedghi

can you try again with latest master?

sedghi avatar Mar 15 '24 14:03 sedghi

I've ran into this too, and I think it can be explained by an issue with how y'all are shipping / bundling type declarations in your final distribution packages (via NPM).

For example, if take a look at @ohif/core's package.json file, I see that the types entrypoint points to src/types/index.ts:

https://github.com/OHIF/Viewers/blob/df32a05a4d64878c3aaccb54c4b19665ffa58788/platform/core/package.json#L10

However, the final distribution bundle on NPM does not include the src directory at all - only dist, so the TypeScript compiler is not going to be able to resolve those type declarations:

npm pack --dry-run @ohif/[email protected]

# npm notice === Tarball Contents ===
# npm notice 1.1kB   LICENSE
# npm notice 6.4kB   README.md
# npm notice 585.6kB dist/ohif-core.umd.js
# npm notice 716B    dist/ohif-core.umd.js.LICENSE.txt
# npm notice 1.6kB   package.json
# npm notice === Tarball Details ===

FWIW, I've noticed this issue with multiple OHIF packages - @ohif/core and @ohif/extension-cornerstone at the very least both have this issue.

joshuatz avatar Apr 13 '24 02:04 joshuatz

Any solution to this ?

jsibrel avatar Jun 18 '24 19:06 jsibrel

I fixed something regarding our cli recently, can you double check again please

sedghi avatar Jun 21 '24 15:06 sedghi

Thank you 👍

jsibrel avatar Jun 21 '24 17:06 jsibrel