tomblachut / svelte-intellij

Svelte components in WebStorm and friends

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing files with extension .js instead of .ts

BrianIto opened this issue · 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.

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

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.

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