Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-import is incorrect for grandparent #1653

Closed
j-tai opened this issue Sep 22, 2022 · 3 comments · Fixed by vitejs/vite#10200
Closed

Auto-import is incorrect for grandparent #1653

j-tai opened this issue Sep 22, 2022 · 3 comments · Fixed by vitejs/vite#10200
Labels
bug Something isn't working

Comments

@j-tai
Copy link

j-tai commented Sep 22, 2022

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

  1. npm create vite@latest - select a framework: Svelte - select a variant: JavaScript
  2. Create an empty file src/Bar.svelte
  3. Create a file src/lib/foo/Foo.svelte. Type <Ba, and accept the Bar auto-completion + auto-import.
    → The import is incorrect.
  4. (optional) To see the compiler error, Foo needs to be used somewhere. In App.svelte, import it and add a <Foo /> tag, then run npm 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

@j-tai j-tai added the bug Something isn't working label Sep 22, 2022
@dummdidumm
Copy link
Member

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.

dummdidumm added a commit to dummdidumm/vite that referenced this issue Sep 22, 2022
The setting would need an accompanying Vite alias, which sounds like too much for a minimal starter template

Fixes sveltejs/language-tools#1653
@dummdidumm
Copy link
Member

Closing as the related PR in create-vite was merged. To remove the buggy behavior, remove the "baseUrl" from your tsconfig.json

@j-tai
Copy link
Author

j-tai commented Sep 26, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants