214

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
  • 2,455
  • 2
  • 13
  • 19
  • If you happen to be inside of a Git repo, and you wish to identify all files that have this problem, then [see this question](https://stackoverflow.com/q/67589775/184546). – TTT Mar 20 '23 at 17:30

29 Answers29

269

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
  • 16,949
  • 9
  • 76
  • 114
144

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.

miken32
  • 42,008
  • 16
  • 111
  • 154
nima
  • 7,796
  • 12
  • 36
  • 53
116

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,730
  • 1
  • 20
  • 27
  • 1
    Notice that TS may throw an error on both the wrong and right new paths (which is misleading). Make sure to change all imports to the correct one and restart the TS server – Francisco Gomes Feb 01 '23 at 15:38
73

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

So you should have something like that:

{
  "compilerOptions": {
    ...
    "forceConsistentCasingInFileNames": false,
    ...
  }
}
Ruslan Korkin
  • 3,973
  • 1
  • 27
  • 23
  • 3
    I love you. This is exactly what I was looking for. We are doing an upgrade project and don't have time to change the casing of 500+ files. – fahadash Apr 27 '23 at 18:41
48

For VS Code IDE users:

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

mcjai
  • 558
  • 4
  • 9
  • 1
    This *after* you fix all relevant casing errors. Best solution. Don't like to unset "forceConsistentCasingInFileNames" as that may introduce other errors. – rickb Apr 22 '23 at 17:18
  • This works after fixing all the casing errors. – thomasiuz May 19 '23 at 18:05
41

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,825
  • 2
  • 17
  • 12
16

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

James Ikubi
  • 2,552
  • 25
  • 18
8

It's not enough to restart your TS server!

As of 2023, I found a consistent way to reproduce the issue. This error will happen whenever you still have imports pointing to the wrong path! (after renaming)

// Wrong path, but same "Already included file name" error
import { Home } from './home';
// CORRECT path, but same "Already included file name" error
import { Home } from './Home'; // <- new path

Fix all imports path and restart your TS server (on VS Code, press F1 > Restart TS server)

TS team should definetly work on improving this error message :)

Francisco Gomes
  • 1,411
  • 12
  • 13
6

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

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,645
  • 3
  • 34
  • 51
5

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
  • 1,561
  • 16
  • 12
3

For me the problem only went away:

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

Even after changing cases and making git config ignore case false(git config core.ignorecase false) still I had to follow the following then only it worked as expected!

git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push origin master

Thanks to this comment: https://stackoverflow.com/a/55541435/3272407

Rahimuddin
  • 458
  • 5
  • 15
1

To fix the error, make sure your import statement is pointing to the correct file. If it is and you still get the error, then Restart your IDE

1

This is the ONLY solution that worked for me!

  • OS: windows
  • IDE: VSCode
  • Project: React + jsconfig.json

The Case Problem

So I had a FOLDER! renamed, not a FILE!. Major difference !
Consider the following folder structure:

*** INITITAL STATE - BEFORE RENAMING ***

|-Highcharts
|
|___  BarChart
|   |
|   |__ index.jsx
|   |__ getBarChartOptions.js
*
*
* * * *

Next thing I did was to rename "Highcharts" to "highcharts", and things started to get nasty. That error popped-up like crazy. That ONE LETTER going from uppercase to lowercase drove it mad!
One place where that lint error came from was a relative import within index.jsx that called getBarChartOptions.js.

// The insides of the index.jsx file

import { getOptions } from './getBarChartOptions';
.
.
.

Solution - The trick that did it:

As someone here said, You need to rename your file (folder in my case) to another name, and once again back to its original name.
BUT !!!
IF it is a folder? You also NEED to rename OTHER SUB-FOLDERS along the way! It's a RECURSIVE PROCESS if you also have sub-folders! So in my case I also had to rename BarChart (look at the folder tree above) as well to another name, and once again back to its original name, before the error went away completely. Changing the root cause folder (highcharts in this case) was simply not enough. I sincerely hope that it would help someone else out there.

Tal Kohavy
  • 438
  • 2
  • 8
  • 22
0

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
  • 1,145
  • 11
  • 21
0

I had the same issues but it came from the imports inside test files (which were based on jest). Solution was to clear the jest cache using the following command.

 node ./node_modules/jest/bin/jest.js --clearCache
Chim
  • 277
  • 1
  • 3
  • 9
0

In my case, i have made the changes locally on windows and my git was configured to ignore the casing changes to filenames. When these changes went into the CI Build on linux machine using GitHubActions, it finds the new path in file imports, but does not find the matching files with exact path name(case-sensitive).

Solution in my case was to use git config core.ignorecase false So that git detects such changes and prompts us to push.

Yogesh Kumar Gupta
  • 1,009
  • 1
  • 10
  • 10
0

I had just had this occur with Vue and Visual Studio Code. It was telling me random Vue files 'Already included file name { file name } differs from file name { file name } only in casing.'

I simply restarted Visual Studio Code and the problem went away.

22289d
  • 81
  • 1
  • 7
  • Re-typing the import statement also makes that error message go away (just happened to me and thats how I fixed it) – doozy Jul 27 '23 at 22:26
  • I am getting other weird errors in Visual Studio Code now with Vue, I suspect there is some kind of VSC bug. For example it's not recognizing Pinia stores in Components. And this bug in my answer keeps returning. – 22289d Jul 27 '23 at 23:03
0

For me, this was because I had accidently uppercased one of my routes, i.e. Positive instead of positive and then corrected it. However, SvelteKit still had the old version cached. So what you need to do is:

  1. Delete the .svelte-kit/types/src/routes/path/to/your/Route folder. This will remove the old, wrong types.
  2. Run npm run dev to make SvelteKit generate the new, correct types.

Hope this helps!

cegredev
  • 1,485
  • 2
  • 11
  • 25
0

In my case error was :

File name 'c:/Users/yourUserName/projectName/src/Components/Navbar/Navbar.jsx' differs from already included file name 'c:/Users/yourUserName/projectName/src/Components/Navbar/navbar.jsx' only in casing. The file is in the program because: Root file specified for compilation Imported via "./Components/Navbar/Navbar" from file 'c:/Users/userName/projectName/src/App.js ts1149)

I always keep the directory name starting with a smaller character and file name starting with a capital character.
However this time I kept it identical. I updated it as per the aforementioned statement.
And then just restarting the IDE solved the error msg.


Update : Later I figured out small and capital chars doest matter. Just restarting the IDE also works fine.

Lakshay Rohilla
  • 1,654
  • 6
  • 9
  • 30
0

As @Roslan Korkin alluded to, the issue seems to be a bug with the TS server. You can resolve it by turning off the forceConsistentCasingInFileNames option in the tsconfig.json file. But you may still want to have that option turned on.

In that case, follow these instructions:

  1. In the tsconfig.json file, set forceConsistentCasingInFileNames to false
  2. Stop the server if running.
  3. Revert to the original option, forceConsistentCasingInFileNames to true
  4. Restart the server
Courtney
  • 309
  • 2
  • 10
-1

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
  • 2,455
  • 2
  • 13
  • 19
-1

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

Incorrect:

import React from "React";

Correct:

import React from "react";
Shafqat
  • 1,104
  • 1
  • 11
  • 17
-1

Writing the import again worked for me.

Lim
  • 753
  • 14
  • 31
Marco Mesen
  • 653
  • 6
  • 12
-1

Remove .vue extension and it worked

-1

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
  • 526
  • 3
  • 19
-1

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
  • 656
  • 1
  • 6
  • 14
-1

For Visual Stuido Code user, Restart TS Server fixed my issue without rebooting the whole VS code.

Mengnan
  • 62
  • 3