-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
Thanks for your efforts.
From the docs here: https://kit.svelte.dev/docs/configuration#alias
An object containing zero or more aliases used to replace values in import statements. These aliases are automatically passed to Vite and TypeScript.
I'm led to believe the kit.alias config is the one-stop destination for all things aliases. To my observation, it only impacts the aliases built by npx svelte-kit sync and output to .svelte-kit/tsconfig.json. This helps with import intellisense and ESLint checks, but Vite apparently is not made aware of the aliases.
Reproduction
- Go to https://stackblitz.com/edit/sveltekit-alias?file=svelte.config.js&terminal=dev
- Observe configs in svelte.config.js
- Run
npm run dev(should start automatically) and note the error
Logs
Cannot find module '$components/Hello.svelte' imported from '/home/projects/sveltekit-alias/src/routes/+page.svelte'System Info
System:
OS: Linux 5.0 undefined
CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.10 - /bin/yarn
npm: 7.17.0 - /bin/npm
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.64
@sveltejs/kit: next => 1.0.0-next.413
svelte: ^3.46.0 => 3.49.0
vite: ^3.0.0 => 3.0.8Severity
serious, but I can work around it
Additional Information
By applying aliases in both [email protected] and [email protected] I am able to have Typescript and Vite acknowledge my aliases.
Here is the workaround applied: https://stackblitz.com/edit/sveltekit-alias-workaround?file=svelte.config.js,vite.config.js&terminal=dev
Convenience link to Vite docs: https://vitejs.dev/config/shared-options.html#resolve-alias