Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'File name differs from already included file name only in casing' on relative path with same casing

Error TS1149: File name 'C:/Project/frontend/scripts/State.ts' differs from already included file name '../frontend/scripts/State.ts' only in casing.

I've triple checked the casing in our references and the actual files have the correct casing as well. As far as I can tell, this is solely because the relative path uses incorrect casing, or perhaps it's just because of the relative path itself?

The thing is, it compiles just fine on Mac and Linux, but throws this error on Windows.

If it helps, forceConsistentCasingInFileNames is enabled in the tsconfig, and we're using tsify to compile.

like image 978
zuddsy Avatar asked Jul 05 '18 18:07

zuddsy


11 Answers

For me, the issue occurred when a file was quickly renamed from someFile.ts to SomeFile.ts. Restarting my IDE (Visual Studio Code) made the warning go away.

like image 115
Paul Razvan Berg Avatar answered Oct 03 '22 23:10

Paul Razvan Berg


In my case, the error was in the import statement. The import statement had a capital letter instead of small letter, which worked during develop in Windows, but not when compiling for production.

wrong:

import {SomeClass} from '/some/path/SomeClass.ts';

correct:

import {SomeClass} from '/some/path/someClass.ts';
like image 36
Martin Åhlin Avatar answered Oct 03 '22 21:10

Martin Åhlin


UPDATE 2021

That's a weird error that occurred in my IDE, but it can be simply done with two simple steps:

rename your file (not component) to another name and once again back to your original name.

Example:

consider we have a myFile.js file in the components directory:

> src
   > components
       > myFile.js

First

Rename myFile.js into another name (anything) like temp.js:

myFile.js    ---->    temp.js

Second

back to its original name,

temp.js    ---->    myFile.js

It's also work fine with *.ts *.tsx *.js *.jsx extensions.

like image 33
nima Avatar answered Oct 03 '22 22:10

nima


You need to disable the "forceConsistentCasingInFileNames" in the tsconfig.json file.

So you should have something like that:

{
  "compilerOptions": {
    ...
    "forceConsistentCasingInFileNames": false,
    ...
  }
}
like image 35
Ruslan Korkin Avatar answered Oct 03 '22 22:10

Ruslan Korkin


Restarting VS Code IDE didn't work for me and I didn't want to change config files. These are the steps that worked for me to resolve this problem:

  1. From VS Explorer, rename the problem file to a new name
  2. Change the component name to the new name inside the file
  3. Save the file
  4. Restart VS Code
  5. Rename the file back to the name I originally wanted
  6. Change the component name to match

It must be some kind of caching issue inside VS Code

like image 38
ttemple Avatar answered Oct 03 '22 23:10

ttemple


For VS Code IDE users:

You can fix it by opening the Command Palette (Ctrl+Shift+P) --> Select Typescript: Restart TS server.

like image 41
mcjai Avatar answered Oct 03 '22 23:10

mcjai


Mine was a vue problem, I removed the .vue extension and it worked

like image 36
james ace Avatar answered Oct 03 '22 23:10

james ace


When two files exist in same folder with names like a.tsx and A.tsx you will get this error

like image 28
Dinesh Khetarpal Avatar answered Oct 03 '22 21:10

Dinesh Khetarpal


Ok, just need to throw in my "solution" here as well, since it was different from the others. The error message clearly said where it saw an error. It was the casing of a directory that had been renamed (from Utils -> utils). Even though it was renamed correctly everywhere I still got the error. My solution was to rename it once more (why not, hehe) to utils2. After that it worked fine

like image 23
Cowborg Avatar answered Oct 03 '22 22:10

Cowborg


For VS Code, only thing worked for me was to clear editor history:

  1. Press Ctrl + Shift + P.
  2. type command Clear Editor History.
  3. Press Enter.
like image 5
Konrad Grzyb Avatar answered Oct 03 '22 22:10

Konrad Grzyb


I've tried these two ways:

  1. Import file with '@/frontend/scripts/State.ts' instead of '../frontend/scripts/State.ts'. It works only if you are using path alias.

  2. Rename the directory of the project and open the project from the new directory.

like image 1
yancaico Avatar answered Oct 03 '22 22:10

yancaico