Reputation: 541
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).
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.
Upvotes: 13
Views: 29374
Reputation: 832
I resolved this problem by removing all the path
definitions from tsconfig.json files.
Upvotes: 1
Reputation: 1
I had the same issue with my next.JS project and it has gone after restarting VS code.
Upvotes: 0
Reputation: 721
This is how I usually solve these errors:
npm run check
to help the compiler figure out where things are.npm run build
Upvotes: 23
Reputation: 1580
I was getting this error in VS Code. After closing and reopening VS Code the error is gone.
Upvotes: 11
Reputation: 4522
A few things to try:
header.svelte
or Header.svelte
?)npm run prepare
if you've recently created src/lib
..svelte-kit/tsconfig.json
(or jsconfig.json
) and make sure you see path
aliases for $lib
.Upvotes: 1