-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Describe the bug
When installing Svelte via an alias in package.json, TypeScript type resolution fails.
This happens because Svelte currently relies on ambient module declarations in a single dts file (e.g., declare module 'svelte/compiler' { ... }). These hardcoded module names do not automatically adjust to the package alias (e.g., svelte5/compiler).
Furthermore, build tools like tsdown or tsup cannot correctly analyze these ambient types for bundling or dts generation.
Suggestion
I suggest moving away from the monolithic declare module approach. A more modern and compatible structure would be to use separate .d.ts files alongside their respective entry points.
Current Structure (simplified):
// types/index.d.ts
declare module 'svelte/compiler' { /* ... */ }
declare module 'svelte/action' { /* ... */ }Proposed Structure:
dist/
index.js
index.d.ts
compiler.js
compiler.d.ts
This change would allow TypeScript to resolve types relative to the file location, making the package agnostic to its installed name.
Relate issue: sxzz/rolldown-plugin-dts#170
Reproduction
- Create a new project.
- Install Svelte with an alias:
pnpm install svelte5@npm:svelte@5. - Try to import from the compiler:
import {} from 'svelte5'
- Observation: TypeScript throws an error:
File '/proj/node_modules/.pnpm/svelte@5.48.0/node_modules/svelte/types/index.d.ts' is not a module
Logs
System Info
N/ASeverity
annoyance