Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Typescript detect import path error with a case sensitive typo?

Typescript didn't detect this typo error (case sensitive).

The name of the file: AdminTextArea

The import with the typo import AdminTextArea from "@components/AdminTextarea"

The typo is: area instead of the correct word Area.

My Typescript environment didn't complain about this at all.

enter image description here

No errors are shown and it runs smoothly.

It was only after I've transpiled it to JS with babel and sent it to run on my Docker container on the cloud, that it triggered this error:

enter image description here

The path is perfect, except for the typo.

What can I do to detect this error in my dev Typescript environment? Is this an eslint thing or is my Typescript not configured correctly?

like image 681
cbdeveloper Avatar asked Oct 16 '25 01:10

cbdeveloper


2 Answers

This is operating-system dependent. Some operating systems have a case-insensitive file system (MacOS would be the primary example). Linux file systems are case-sensitive, so this error may manifest when moving from a case-insensitive file system to one that is case-sensitive.

Unfortunately, TypeScript can't do much about this since it depends on the file system itself. You can add this compiler setting:

{
  "compilerOptions": {
    "forceConsistentCasingInFileNames": true

This may help detect this error.

like image 127
Explosion Pills Avatar answered Oct 18 '25 01:10

Explosion Pills


With ESLint rule import/no-unresolved you can make sure that case sensitive imports are added correctly.

like image 28
hendrixchord Avatar answered Oct 17 '25 23:10

hendrixchord



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!