Svelte automatic imports do not work in Visual Studio Code

160 views Asked by At

In preview application I was working on when I typed the name of the component. Like this: I gave an import. Automatically added to script.

`<BaseSelect options={optionsDifficulty} defaultValue={defaultDifficultValue} on:change {handleDifficultChange}> </BaseRadio>
import BaseSelect from '$lib/Inputs/BaseSelect.svelte';

`

I did not write anything. It has just appeared. But in my new project it is not working. I need to write the import manually. Do you guys know how to setup this automatic import? I do not like autoimport way. Because I do not see the imports so I do not have control over it.

I tried autoimport as an extension, but it does not show list of imports.

My IDE is Visual Studio Code.

1

There are 1 answers

0
user2062778 On

Finally I solved it. All the solutions were about adding to tsconfig.json. But I have javascript, not typescript. I added jsconfig.json (instead of tsconfig.json) in the main root of the project (next to package.json). And in it I added:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "$lib":["src/lib"],
            "$lib/*":["src/lib/*"]
        }
    },
    "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}