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 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
Initialize a standard SvelteKit project with TypeScript enabled.
Modify svelte.config.js and add an alias to the kit configuration as follows:
In my HeaderLeft.svelte component, which is located here: "src/lib/layouts/main/HeaderLeft.svelte"
By using the added "$routes" alias, the import seems to works properly:
import type { LayoutData } from '$routes/[[lang=langCode]]/$types';
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 have also tried different alias paths to see if it might work, but it didn't work.
$routes: './svelte-kit/types/src/routes'
$routes: './.svelte-kit/types/src/routes'
and so on...
Either the import via $route didn't resolve anymore or if "." is added in front then i get the other error message: "Non-relative paths are not allowed when 'baseUrl' is not set."
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
npm run dev -- --host
> project@0.0.1 dev
> vite dev --host
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 VITE v5.2.8 ready in 984 ms
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
By using the added "$routes" alias, the import seems to works properly:
import type { LayoutData } from '$routes/[[lang=langCode]]/$types';
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.
$routes: './svelte-kit/types/src/routes'
$routes: './.svelte-kit/types/src/routes'
and so on...
Either the import via $route didn't resolve anymore or if "." is added in front then i get the other error message: "Non-relative paths are not allowed when 'baseUrl' is not set."
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
The text was updated successfully, but these errors were encountered: