jamesbirtles / svelte-vscode

Svelte language support for VS Code
https://marketplace.visualstudio.com/items?itemName=JamesBirtles.svelte-vscode
MIT License
207 stars 22 forks source link

File *.svelte is not a module is thrown when using TypeScript preprocessor #90

Closed federicocarboni closed 4 years ago

federicocarboni commented 4 years ago

File /path/to/file.svelte is not a module is thrown when using the TypeScript preprocessor. Here's my svelte.config.js

module.exports = {
  preprocess: require('svelte-preprocess')(),
};

tsconfig.json

{
  "compilerOptions": {
    "types": ["svelte"]
  }
}

What am I doing wrong? Screenshot

federicocarboni commented 4 years ago

it compiles correctly using svelte-preprocess and rollup-plugin-typescript2

cajames commented 4 years ago

Might need to define the module for .svelte files in VSCode.

Try adding this file to your project:

// svelte.d.ts
declare module "*.svelte" {
  const value: any; // Add better type definitions here if desired.
  export default value;
}
benbot commented 4 years ago

Shouldn't something like that declaration be automatically understood?

I shouldn't need to add a type def file to tell svelte-vscode that svelte files contain modules, right?

thlcodes commented 4 years ago

@cajames solution did not work for me. I tried both adding "svelte" to types in tsconfig and adding a type definition for *.svelte, neither worked. Still getting "no default export" or "not a module" error, but only in VSCode. Same with @pyoner/svelte-ts-preprocess

JakubKoralewski commented 4 years ago

Same here. Also, duplicate of #64.

EDIT: Not duplicate, but similar. Sorry.

danawoodman commented 4 years ago

Any updates to this?