You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Svelte component imports a type with the same name as itself, invalid types are generated by svelte-package because the type import is included in the file and it conflicts with the generated type for the component.
// File: Source.svelte.d.ts// This is incorrectly includedimporttype{Source}from"./types.js";// This is correct but conflicts with the above type importdeclareconstSource: import("svelte").Component<Record<string,never>,{},"">;typeSource=ReturnType<typeofSource>;exportdefaultSource;
When trying to import this component from the package, you then see an error like
Error: 'Source' resolves to a type-only declaration and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
If this is hard to fix for some reason, it would be nice if there was a way to detect this and raise an error during packaging.
Note that it includes the import { Source } from './types.js and this conflicts with the exported type from the component. There's no reason for that import to be present in the generated Source.svelte.d.ts, and indeed with Svelte 4 I believe it was not.
The reproduction uses Vite 6 but it also happens with Vite 5, which may not be relevant for svelte-package anyway.
Describe the bug
When a Svelte component imports a type with the same name as itself, invalid types are generated by svelte-package because the type import is included in the file and it conflicts with the generated type for the component.
Source
Generated Types (annotated)
When trying to import this component from the package, you then see an error like
If this is hard to fix for some reason, it would be nice if there was a way to detect this and raise an error during packaging.
Reproduction
https://github.com/dimfeld/svelte-package-type-name-bug
pnpm install && pnpm package
dist/Source.svelte.d.ts
Note that it includes the
import { Source } from './types.js
and this conflicts with the exported type from the component. There's no reason for that import to be present in the generatedSource.svelte.d.ts
, and indeed with Svelte 4 I believe it was not.The reproduction uses Vite 6 but it also happens with Vite 5, which may not be relevant for svelte-package anyway.
Logs
No response
System Info
Severity
annoyance
Additional Information
Workaround is just to rename the import to something else.
import { Source as MySource } from './types.js'
or similar.Originally encountered in dimfeld/svelte-maplibre#222
The text was updated successfully, but these errors were encountered: