109

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.

zuddsy
  • 1,367
  • 2
  • 9
  • 19

18 Answers18

113

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.

Paul Razvan Berg
  • 10,820
  • 7
  • 50
  • 86
76

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';
Martin Åhlin
  • 2,102
  • 18
  • 27
47

UPDATE 2021

That's a wired 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.

nima
  • 6,005
  • 8
  • 32
  • 48
36

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

So you should have something like that:

{
  "compilerOptions": {
    ...
    "forceConsistentCasingInFileNames": false,
    ...
  }
}
Ruslan Korkin
  • 2,460
  • 1
  • 24
  • 20
  • for some reason in my dev environment, it was working fine by default, but in production-build (Docker, alphine-linux) it was bugging. I found that making this flag to true, makes it consistently bugging, which is what I want. :) Thanks! – Aidin Dec 20 '21 at 21:24
30

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

ttemple
  • 1,531
  • 1
  • 14
  • 12
14

For VS Code IDE users:

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

mcjai
  • 208
  • 2
  • 7
9

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

james ace
  • 1,693
  • 18
  • 10
  • 1
    in case anyone else has the same problem in Vue, I can vouch this solves the error, at least in Vue3. – nos codemos Oct 10 '20 at 11:25
  • This actually works. Have you any idea why? This has to go down as one of the weirdest bugs to ever walk this earth, lol. – Igiri David Sep 07 '21 at 17:42
5

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

Cowborg
  • 2,209
  • 2
  • 27
  • 40
4

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

  • This was the case for me. I had app.js and App.test.js and was getting this error when importing from app.js- 'app.js' differs from already included file name '/src/App.js' only in casing. ts(1149) Lowercasing App.test.js fixed it. – Steve Nov 03 '20 at 20:46
  • Same for me. For some reason duplicated files were only present in github and heroku was failing on build with this error. Thx – emcee22 Dec 22 '20 at 23:04
3

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.
Konrad Grzyb
  • 843
  • 10
  • 10
1

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.

yancaico
  • 989
  • 8
  • 16
0

Changing "React" to "react" worked for me.

Incorrect:

import React from "React";

Correct:

import React from "react";
Shafqat
  • 1,086
  • 1
  • 11
  • 16
0

Writing the import again worked for me.

Lim
  • 661
  • 13
  • 28
Marco Mesen
  • 492
  • 4
  • 9
0

Remove .vue extension and it worked

Ahkmy990
  • 87
  • 5
0

If nothing works try:

  • Remove node_modules
  • Restart Vetur
  • yarn or npm i again to get your node_modules
  • Restart developer window

Renaming files or restarting didn't help. The error started after renaming a file and letting Vetur do it's thing with imports.

Davo
  • 536
  • 3
  • 18
0

In my case, I am using Nextjs. Removing the .next folder and starting the app again solved the problem.

Update: The error occurred again. This time deleting .next didn't help. Turned out it was due to a circular dependency in my code.

Peter
  • 540
  • 5
  • 12
0

For me the problem only went away:

  1. Close VS Code
  2. Deleting the node_modules\.cache folder.
  3. Re-open VS Code
-2

The answer was that we were using tisfy 1.0.1, when forceConsistentCasingInFileNames wasn't supported until 4.0.0. Updating fixed the issue.

zuddsy
  • 1,367
  • 2
  • 9
  • 19