sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.26k stars 200 forks source link

Wrong path is resolved when the imports differ in case only #1882

Open mdorda opened 1 year ago

mdorda commented 1 year ago

Describe the bug

When there are 2 imports which differ in case only, svelte-check resolves the path wrongly. Eg:

index.ts

import { Favs } from '@core/Favs'; // import 1
import favs from '@core/favs'; // import 2

It fails with an error

Module '"path/to/named/folder/core/Favs"' has no default export.

But it has default export for sure, TS type check works like a charm.

core/Favs.ts

export const Favs = 'I am Favs class';

core/favs.ts

export default 'I am favs utils';

The order counts, when you change index.ts file as following:

import favs from '@core/favs'; // import 2
import { Favs } from '@core/Favs'; // import 1

The error changed to:

Module '"@core/favs"' has no exported member 'Favs'. Did you mean to use 'import Favs from "@core/favs"' instead?

Reproduction

See "Describe the bug" section

Expected behaviour

It should resolve both paths correctly, as tsc does.

System Info

Which package is the issue about?

svelte-check

Additional Information, eg. Screenshots

No response

jasonlyu123 commented 1 year ago

macOS is case-insensitive by default. Did you enable file system case sensitivity? You mentioned both local and CI OS. Do this means it happens in both cases, or is there an inconsistency between them? If it's the latter, is this error from CI or local? And the last one, what do mean by "as clean TS does?" Did you try tsc and the error doesn't happen?

mdorda commented 1 year ago

I apologize for the confusion. On Debian in pipeline everything works correctly, my mistake (I edited the post). The problem is only locally on macOS. However, tsc builds the same code on Mac without any issue. The issue can be "hotfixed" for svelte-check with @ts-ignore:

import { Favs } from '@core/Favs';
// @ts-ignore
import favs from '@core/favs';

But I wonder why tsc is ok with that. Moreover, it works as expected until svelte-check 2.9.2. The bug starts appearing only from version 2.10.0.

ilblog commented 1 year ago

I have macOS and I do confirm the BUG

Everything accepts case sensitivity: tsc git, excepts of latest version of svelte-check

jasonlyu123 commented 1 year ago

We need more info on this. How do you configure your file system case sensitivity? Does this happen in both editor and svelte-check? What package manager are you using?

mdorda commented 1 year ago

How do you configure your file system case sensitivity?

I have made no changes, so it is not a case sensitive file system by default

Does this happen in both editor and svelte-check?

Editor is ok, no error. Only svelte-check.

What package manager are you using?

npm 9.2.0