Closed teneon closed 4 hours ago
using "$types":"/.svelte-kit/types/src/routes"
solves the issue for me.
The issue is caused by this line https://github.com/sveltejs/kit/blob/0fee61c571db253921d1a6503fc879235c6f3b60/packages/kit/src/core/sync/write_tsconfig.js#L212 that strips the ".svelte-kit/" from ".svelte-kit/types/src/routes". Hence, you end up with $routes: "types/src/routes"
in the generated tsconfig.json which is a non-relative path and causes the tsconfig.json error. You can see this in .svelte-kit/tsconfig.json
.
Describe the bug
When attempting to use kit.alias to set aliases for TypeScript types in the .svelte-kit/types/src/routes directory, TypeScript fails to recognize these aliases unless baseUrl is explicitly set in tsconfig.json. However, setting baseUrl directly conflicts with SvelteKit's built-in behavior of generating tsconfig.json, leading to a warning against such modifications. This creates a challenging scenario where users are unable to utilize custom aliases for auto-generated types, impacting development workflow and code organization.
Reproduction
Without alias i need to import it relative like this and it is cumbersome: import type { LayoutData } from '../../../routes/[[lang=langCode]]/$types';
The issue is that if i add that alias, i also get VSCode error tsconfig.json: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?
If i add baseUrl to the tsconfig.json i get a warning when i do "npm run dev" i get the following message: "You have specified a baseUrl and/or paths in your tsconfig.json which interferes with SvelteKit's auto-generated tsconfig.json. Remove it to avoid problems with intellisense. For path aliases, use
kit.alias
instead: https://kit.svelte.dev/docs/configuration#alias"So this surely isn't the right way.
I am not sure if this is a bug / a missing feature or if i don't understand something and i am doing it totally wrong. Please help! Thank you in advance! :)
best regards, Jim
Logs
System Info
Severity
annoyance
Additional Information
No response