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

moduleResolution: "bundler" support #68

Closed
hjsung-brique opened this issue Nov 28, 2023 · 3 comments
Closed

moduleResolution: "bundler" support #68

hjsung-brique opened this issue Nov 28, 2023 · 3 comments

Comments

@hjsung-brique
Copy link
Contributor

hjsung-brique commented Nov 28, 2023

I tried use svelte-flatpickr with tsconfig.json setting as below:

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		...
		"module": "ESNext",
		"moduleResolution": "Bundler",
		"types": ["vitest/globals"]
	}
}

When I import module as
import Flatpickr from 'svelte-flatpickr';
and executed npm run check, I see error :

Error: Cannot find module 'svelte-flatpickr' or its corresponding type declarations. (ts)
        import Flatpickr from 'svelte-flatpickr';

It was because "moduleResolution": "Bundler" option in tsconfig.json makes fail to find type definitions. (https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution)

I tried to fix package.json file of svelte-flatpickr module as below, and error resolved.

{
     ...
      "exports": {
		".": {
			"svelte": "./src/Flatpickr.svelte",
			"types": "./src/types.d.ts"
		}
	}
}

How about adding "types" field to svelte-flatpickr module's package.json file?

@jacobmischka
Copy link
Owner

LGTM, do you mind submitting a PR?

hjsung-brique added a commit to hjsung-brique/svelte-flatpickr that referenced this issue Nov 28, 2023
fix of issue jacobmischka#68 : moduleResolution: "bundler" support
jacobmischka added a commit that referenced this issue Nov 28, 2023
@jacobmischka
Copy link
Owner

Thank you! Should be released in 3.3.4.

@hjsung-brique
Copy link
Contributor Author

hjsung-brique commented Nov 29, 2023

After PR, I reviewed official svelte site about packaging (https://kit.svelte.dev/docs/packaging#typescript), and found that they recommend add "typesVersions" field to package.json entries like :

{	"exports": {
		"./foo": {
			"types": "./dist/foo.d.ts",
			"svelte": "./dist/foo.js"
		}
	},
	"typesVersions": {
		">4.0": {
			"foo": ["./dist/foo.d.ts"]
		}
	}
}

As I use typescript version 5.0.0, it was fine without "typesVersions" field. For anyone using lower version of typescript, "typesVersions" field might necessary. I hope it helps for later updates.

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

2 participants