svelte-intellij icon indicating copy to clipboard operation
svelte-intellij copied to clipboard

Importing files with extension .js instead of .ts

Open BrianIto opened this issue 2 years ago • 1 comments

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.

BrianIto avatar Sep 03 '22 15:09 BrianIto

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

srsholmes avatar Sep 13 '22 19:09 srsholmes

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.

shirotech avatar Nov 30 '22 16:11 shirotech

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

tomblachut avatar Jul 04 '23 17:07 tomblachut