Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS extension Svelte for VS Code introduced errors in Version 109.00 on MacOS : absolute paths + tsconfig.json #2486

Closed
ayaphi opened this issue Sep 5, 2024 · 5 comments · Fixed by #2488

Comments

@ayaphi
Copy link

ayaphi commented Sep 5, 2024

Describe the bug

(1) Svelte components imports that use absolute paths, create a cannot find module or its corresponding type declarations ts(2307) error in VS Code. Relative path imports work fine.

VS Code Errors

(2) Opening tsconfig.json creates an error message : No svelte input files were found in config file „…/tsconfig.json“. Did you forget to add svelte files to the 'include' in your tsconfig.json? Specified 'include' paths were '["**/*.ts"]' and 'exclude' paths were ‚undefined'

Reproduction

Use Svelte for VS Code version 109.00 on MacOS 14.6.1

Downgrading to the latest version 108.6.1, everything works as expected.

Expected behaviour

The errors should not appear - sounds silly, but that's it ;-).

System Info

VS Code Version 1.92.2 on MacOS 14.6.1.

Which package is the issue about?

No response

Additional Information, eg. Screenshots

No response

@ayaphi ayaphi added the bug Something isn't working label Sep 5, 2024
@dummdidumm
Copy link
Member

Please provide a reproduction. The bare minimum would be the copy-pasted code of the file in question and your tsconfig.json.

@jasonlyu123
Copy link
Member

This is likely similar to #2485 where the include config in your tsconfig.json doesn't match any svelte files and your svelte file is treated as if there isn't a tsconfig.

@jasonlyu123 jasonlyu123 added awaiting submitter and removed bug Something isn't working labels Sep 6, 2024
@bf-software
Copy link

bf-software commented Sep 7, 2024

I'm having the same issue: the new vscode extension for svelte (v109.0.0) ignores the "paths" entry in tsconfig and breaks all "non-relative" imports in my .svelte modules.

It also introduces that error about "No svelte input files were found...". You can satisfy that error by explicitly including at least one .svelte file in tsconfig, but although that stops the tsconfig error, it doesn't fix the broken imports in all svelte files the that use a "paths"-based, "non-relative" module import. By the way, I shouldn't need to do this since all of my .svelte modules are imported with import statements. (the svelte extension v108.6.1 works fine.)

tsconfig.json
OS: Windows 10

<script lang="ts">
  import AccountTree from './components/AccountTree.svelte';
  import Sizer from '@bf-s/client/components/Sizer.svelte';   // <-- Cannot find module '@bf-s/client/components/Sizer.svelte' or its corresponding type declarations.ts(2307)
  import AccountTreeToolbar from './components/AccountTreeToolbar.svelte';
  ...

@jasonlyu123
Copy link
Member

jasonlyu123 commented Sep 7, 2024

It might be you just need to restart the editor after adding svelte file to the config. We can check if something can be improved.

I shouldn't need to do this since all of my .svelte modules are imported with import statements

We're considering about changes related to this. But having svelte file in the include is still preferred. It'll be more consistent and performant.

the svelte extension v108.6.1 works fine.)

This is that the breaking change and the "no svelte input" is for. Previously svelte file is always put into the nearest tsconfig regardless for the include config.

@bf-software
Copy link

Actually, I see now that only the .svelte files that are explicitly imported via tsconfig are fixed and handle the paths correctly.

However, I don't want to use tsconfig that way. Yes it is more performant to include everything via tsconfig, but tsc will work fine when only including your application's entry point in tsconfig. (and then tsc will parse, discover, and include other modules as it finds them in import statements.)

The reason I do it that way is because I'm pulling modules from a large local code library and many modules will not be used for any given project, so I don't want to do any blanket includes like include:["src/myLibrary/**/*.svelte"]. And, if not using blanket includes, I don't want to have to both specify the modules as imports in the code, AND as individual includes in tsconfig.

I guess the bottom line is: tsc includes its modules either by explicitly declaring them in tsconfig, or via discovering them via the code's import statements. Shouldn't the svelte extension adhere to that as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants