f5 / unovis

Modular data visualization framework for React, Angular, Svelte, Vue, and vanilla TypeScript or JavaScript
https://unovis.dev
Apache License 2.0
2.23k stars 43 forks source link

Cannot find module '@unovis/svelte' or its corresponding type declarations. #343

Closed OTheNonE closed 6 months ago

OTheNonE commented 7 months ago

There is a typescript error when using the svelte part of Unovis:

Cannot find module '@unovis/svelte' or its corresponding type declarations.

The modules works, and the project builds, but the types do not work. Types work though in the TS part of the module. Related to this, i notice in node_modules that the ts-folder has a types.d.ts-file while the svelte-folder has not. Does this have anything to do with this?

This is my tsconfig.json file:

{
    "extends": "./.svelte-kit/tsconfig.json",
    "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "allowJs": true,
        "checkJs": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true,
        "moduleResolution": "Bundler"
    }
}
michaelbelete commented 7 months ago

Any updates? I am facing the same issue 😢

huntabyte commented 7 months ago

It appears the package is missing the "types" from the "exports" statement in the package.json:

{
    "exports": {
        ".": {
+           "types": "./index.d.ts",
            "svelte": "./index.js"
        }
    }
}

Refernece - Svelte packaging docs: https://kit.svelte.dev/docs/packaging#anatomy-of-a-package-json-exports

rokotyan commented 7 months ago

@huntabyte (cc @michaelbelete @OTheNonE) Thanks for pointing it out! I've just published 1.3.6-beta.0, can you please try installing it and confirm if it works?

OTheNonE commented 7 months ago

I can confirm that this specific issue is solved. There is no typescript error, typescript can find the package, and when running npm run check, it displays no errors nor warnings.

Although, i was hoping that this would solve the autocompletion and type infering of some of the svelte components. Specifically, i currently get no autocompletion nor type of "event" when doing <VisAxis tickFormat={(event) => { ... }/>, and there are many other general type problems with all the components. I'll open a new issue.

huntabyte commented 7 months ago

@huntabyte (cc @michaelbelete @OTheNonE) Thanks for pointing it out! I've just published 1.3.6-beta.0, can you please try installing it and confirm if it works?

Awesome, thanks a ton! Would have submitted a PR but was limited on time and realized I needed to submit the CLA.

huntabyte commented 7 months ago

I'm experiencing another related issue when new projects are using "moduleResolution": "NodeNext" the components aren't able to be resolved due to a missing file extension in index.js:

- export * from './containers';
- export * from './components';
+ export * from './containers.js';
+ export * from './components.js';

The ideal approach would be to use "moduleResolution": "NodeNext" in the library's tsconfig.json to ensure regressions aren't introduced and support for both Node and bundlers is provided.

Reference: https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution-for-libraries

https://github.com/f5/unovis/assets/64506580/5e4336d8-5390-485e-b14e-97a5cbd172c0

michaelbelete commented 7 months ago

@huntabyte (cc @michaelbelete @OTheNonE) Thanks for pointing it out! I've just published 1.3.6-beta.0, can you please try installing it and confirm if it works?

@rokotyan 1.3.6-beta.0 fixed my problem. Thank you 🙌🏼

rokotyan commented 7 months ago

@huntabyte @shyakadavis @michaelbelete

1.3.6-beta.1 addresses this problem and ready to be tested, thanks for pointing it out!

We'll need to update Typescript version in our project to use "moduleResolution": "NodeNext" and there were some problems with this. But one day we'll definitely do it.

huntabyte commented 7 months ago

This does fix the issue, thank you!

huntabyte commented 6 months ago

This issue is persisting with the latest version of @unovis/svelte:

It appears this part of the package.json didn't make it into the release:

{
    "exports": {
        ".": {
+           "types": "./index.d.ts",
            "svelte": "./index.js"
        }
    }
}
rokotyan commented 6 months ago

@huntabyte I can't believe we missed it, thanks for reporting. Use 1.4.1-beta.0 as a quick fix