tomblachut / svelte-intellij

Svelte components in WebStorm and friends
MIT License
485 stars 38 forks source link

Importing files with extension .js instead of .ts #310

Closed BrianIto closed 1 year ago

BrianIto commented 2 years ago

I got this problem when using endpoints, creating functions, or something else...

I create a TypeScript file, like this one:

// function.ts

export const sum(a, b) => (a + b)

but when I use the auto-import for the plugin, it happens;

// component.svelte

import { sum } from "./function.js"

causing this error:

Failed to resolve import "./function.js" from "./component.svelte". Does the file exist?

This problem is easy to revert by just changing its extension to .TS, but it's annoying when you have to do it on almost every import, doing it like 200 times. If there's an error with my IDE, please, let me know, I want to fix this problem soon as possible.

Caused by: WebStorm 2022.2.1 OS: macOS Monterrey 12.5.1 Platform: Macbook Air M1 2020.

srsholmes commented 2 years ago

I have the same problem as well, and there is no error to suggest there is anything wrong as well.

shirotech commented 1 year ago

import { sum } from "./function.js"

This is the correct and recommended way to import ts files (type: module in package.json), webstorm and tsc will know that it is referring to a typescript file instead of js, this also reduces any transpilation and only compilation as tsc is a compiler and not a transpiler.

tomblachut commented 1 year ago

Migrated to WEB-54246 Svelte plugin imports using .js extension on TypeScript blocks.