Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module [...] or its corresponding type declarations (js2307) when importing from "$lib" with SvelteKit

Using the latest SvelteKit (1.0.0-next.401) I have a problem importing components from lib using the $lib syntax. I get an error and a red squiggly line (even though the import and web app works fine).

enter image description here

The error message is as follows:

Cannot find module '$lib/components/shared/header.svelte' or its corresponding type declarations. js(2307)

If a use a relative path, the error disappears.

like image 358
Anton Ödman Avatar asked Dec 23 '25 00:12

Anton Ödman


2 Answers

This is how I usually solve these errors:

  • Run npm run check to help the compiler figure out where things are.
  • If it doesn't work reload the code editor can help
  • If all the above fails then try npm run build
like image 119
fcrozatier Avatar answered Dec 24 '25 15:12

fcrozatier


I was getting this error in VS Code. After closing and reopening VS Code the error is gone.

like image 45
JAstuccio Avatar answered Dec 24 '25 14:12

JAstuccio