-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Unable to resolve TS modules with a .js
import path extension if lang="ts"
is missing
#887
Comments
i don't think this is a bug, the file is actually has a .ts extension, not .js. So importing If you import it as Not sure if there is a way to make the error message more descriptive, in my opinion it already is. |
thanks for checking out the issue!
i dont think this is correct, especially when
I completely disagree. Just to check my own sanity, I made a repro and showed it to several people (all of whom are very experienced with TS and Svelte) and none of them were able to find the fix in a reasonable amount of time. i even guided them to inspect the error to see if that would help them solve it. it did not - so it's certainly not descriptive enough on it's own. however, i think it's becoming more clear that this is more of a Vite issue than a |
Thanks for the repro. This seems like a bug in Vite (vitejs/vite#8993) as Svelte only compiles to JS, and the import paths are later resolved by Vite. Frankly though, you should use I'll close this for now as it's an upstream issue. |
thanks @bluwy, I appreciate the insight!
Unfortunately, this sort of conflicts with the recommended setup for creating svelte libraries, which is to use |
Ah true. I forgot about that. I suppose when it comes down to using the right So presumably it should be safe for you to change to |
Describe the bug
Given a TS module,
foo.ts
, we can import this module into a svelte component like so:However, if we were to remove the
lang="ts"
attribute from the script tag:the module will now fail to load, throwing the following error:
...which is a bit unexpected.
If we were to replace the extension for a
.ts
extension instead, the module loads fine:...which is also unexpected, especially when
allowImportingTsExtensions
is not enabled in thetsconfig.json
, causing the LSP to error.This bug was a bit baffling to figure out at first. The warning wasn't particularly helpful in indicating that I was missing the
lang="ts"
attribute either. Either way, this doesn't seem like it's the expected behavior. However, I am unsure if this is directly a Vite issue or avite-plugin-svelte
issue.Reproduction URL
https://github.com/AdrianGonz97/broken-js-import-paths-repro
Reproduction
git clone https://github.com/AdrianGonz97/broken-js-import-paths-repro
pnpm install
pnpm dev
src/lib/JSComponent.svelte
to see the issueLogs
System Info
The text was updated successfully, but these errors were encountered: