Skip to content

$lib imports not working in svelte files in a symlinked project folder #2930

@Titoubiz

Description

@Titoubiz

Describe the bug

I have a SvelteKit project on my Debian machine, and I access it through a symbolic link.

On my editor (Kate, but I have also tried on VS Code), importing anything from the $lib folder into a .svelte file causes this error:

Cannot find module '$lib/example' or its corresponding type declarations.

Importing from $lib into .ts files works well though.

Reproduction

I recreated a SvelteKit + Typescript project from scratch, with this src structure:

src/
├─ lib/
│  ├─ test.ts
│  ├─ test.svelte
│  ├─ example.ts

I export a const value in example.ts, and then import it in the other files. So in my example example.ts contains:

export const example = 1;

And test.svelte:

<script lang="ts">
	import { example } from "$lib/example"; // this import is not resolved
	console.log(example);
</script>

I open my editor with a command like this:

code ~/symlink-to-my-project/src/lib/test.svelte

I let all the other files by default. My attempts to use a preprocessor and aliases in svelte.config.js or to set verbatimModuleSyntax and preserveSymlinks in tsconfig.json didn’t help me.

Expected behaviour

Having no error when I import from $lib folder

System Info

  • OS: Debian
  • IDE: VS 1.108.2 with Svelte for VS Code 109.13.0

Also had the issue with Kate + svelte-language-server 0.17.25

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

Thanks for any help! I can live without using this symlink but I thought it was worth reporting it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions