language-tools
language-tools copied to clipboard
Auto-import is incorrect for grandparent
Describe the bug
When the Svelte plugin auto-imports a component from the grandparent directory, the import it adds is incorrect:
import Bar from 'src/Bar.svelte';
Although this path looks correct, it causes a compiler error:
[vite]: Rollup failed to resolve import "src/Bar.svelte" from "src/lib/foo/Foo.svelte".
The expected import is:
import Bar from '../../Bar.svelte';
Reproduction
-
npm create vite@latest
- select a framework: Svelte - select a variant: JavaScript - Create an empty file
src/Bar.svelte
- Create a file
src/lib/foo/Foo.svelte
. Type<Ba
, and accept theBar
auto-completion + auto-import. → The import is incorrect. - (optional) To see the compiler error,
Foo
needs to be used somewhere. InApp.svelte
, import it and add a<Foo />
tag, then runnpm run build
. → There is a compiler error due to the incorrect import.
Expected behaviour
The auto-import should be correct and should not produce a compiler error.
System Info
- OS: Pop!_OS 22.04
- IDE: VSCodium 1.71.2
Which package is the issue about?
No response
Additional Information, eg. Screenshots
No response
This works as expected from the language-tools side of view. The tsconfig.json
defines a baseUrl
, which in the eyes of TypeScript means these import paths are correct. What's missing is an equivalent of this for Vite, so Vite also knows how to deal with these - this likely means adding an alias.
Keeping this open as a reminder to try this out myself and provide a PR to the Vite repo.
Closing as the related PR in create-vite
was merged. To remove the buggy behavior, remove the "baseUrl"
from your tsconfig.json
Thanks!