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

32

272

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.

Jayme answered 5/7, 2018 at 18:40 Comment(1)
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.Straightedge
J
0

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

Jayme answered 6/7, 2018 at 15:8 Comment(0)
O
363

Solution 1 (worked for me)

The issue occurred when I quickly renamed a file from someFile.ts to SomeFile.ts. Restart your IDE (Visual Studio Code) and the warning will go away.

Solution 2

If you created your file in uppercase and import it in lowercase, the problem still occurs, so check the spelling of the file first.

Offense answered 2/6, 2020 at 19:8 Comment(4)
I did the same thing as op, but for Vetur, it does not go away even after I restart vscodeFaucal
Working on a mapped drive? I had a SharePoint 2019 virtual machine mapped to Z:\ and did a rename. Some kind of caching going on. Closed VSCode & disconnected & reconnected to the SharePoint WebDAV URL and error went away after restarting VSCode.Decemvir
You dont need to restart vs-code, you just need to restart the typescript service or if you have it setup to only use volar, then restart volar. ctrl +shift + p then Typescript: Restart or Volar: RestartSilici
Thank you! Note, also, that if you're using VS Code, you could prolly just do the usual cmd-shift-P (on Mac) and restart TS Server and/or ESLint server if things don't clear up on their own.Subservient
G
192

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.

Guria answered 15/2, 2021 at 9:32 Comment(6)
"Unfortunately", it works... I was hoping for a smarter solution, like force TS to use new casing.Guv
Renaming worked for me, thank you. it's weird, also i noticed that it stated "file name C:\users\Desktop\........... differs from file name C:\users\desktop............ only [...]". Meaning, it read the 2 references with a different "desktop" capital letter. Strange... I don't know (don't think...?) it's somehow due to reinstalling Node? My antimalware removed node files so i had to uninstall and reinstall it...Plagiarize
I can't believe this worked for me as well. I don't enjoy solution such as this, it makes no sense to me :-)Methylal
@NisimNaim exactly, weird :(Guria
Thank you! Working with Svelte and this did the trick!Pathogen
As a reminder, this problem also happens with folder names. Using the same approach would solve the issue.Orlov
D
122

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';
Downey answered 3/5, 2019 at 9:29 Comment(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 serverNorthnortheast
E
91

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

So you should have something like that:

{
  "compilerOptions": {
    ...
    "forceConsistentCasingInFileNames": false,
    ...
  }
}
Essa answered 27/12, 2019 at 13:53 Comment(1)
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.Kial
M
60

For VS Code IDE users:

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

Milkwhite answered 21/10, 2021 at 4:19 Comment(2)
This after you fix all relevant casing errors. Best solution. Don't like to unset "forceConsistentCasingInFileNames" as that may introduce other errors.Dividivi
This works after fixing all the casing errors.Tiercel
P
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

Pry answered 1/9, 2020 at 14:11 Comment(1)
VS code's typescript server does cache the filesystem. You can restart it from the command pallet (Ctrl-Shift-P) and click "TypeScript: Restart TS Server".Retrocede
P
17

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

Personalism answered 5/10, 2020 at 9:17 Comment(0)
N
10

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 :)

Northnortheast answered 30/1, 2023 at 21:33 Comment(1)
Dec 5, 2023, the problem still exists even though I don't use ts in my project at all.Mistymisunderstand
W
6

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

Wynnie answered 27/3, 2020 at 1:7 Comment(1)
I have only one file with this name, where the duplicated file you are talking about is located ? how can it be located ?Dendro
M
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

Monocycle answered 17/3, 2021 at 13:46 Comment(0)
C
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.
Cimbura answered 12/1, 2022 at 14:31 Comment(0)
B
4

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://mcmap.net/q/44965/-how-do-i-commit-case-sensitive-only-filename-changes-in-git

Brahmani answered 14/11, 2022 at 9:38 Comment(0)
W
3

For me the problem only went away:

  1. Close VS Code
  2. Deleting the node_modules\.cache folder.
  3. Re-open VS Code
Whereof answered 20/5, 2022 at 15:20 Comment(0)
T
3

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.

Tarweed answered 27/8, 2023 at 7:26 Comment(1)
This is the exact problem I faced and vscode was just spewing errors in every import statement that used a type alias. The funny thing is this exact setup works on another computer. Unfortunately, restarting the IDE did not fix it for me, I had to update the filename which fixed all the errorsJene
P
2

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.

Platelet answered 7/7, 2023 at 2:28 Comment(0)
G
2

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
Gnosis answered 31/8, 2023 at 4:31 Comment(0)
A
1

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!

Assuage answered 12/8, 2023 at 20:39 Comment(0)
I
1

Using VS Code on a Mac in Dec 2023, my casing does not differ but the error goes away when I first focus on the file with the error in the Explorer and then click on the file it says it can't find.

Inna answered 8/12, 2023 at 5:58 Comment(0)
R
1

I had the same problem. Contrary to my assumption that I thought the problem was from TypeScript, Node.js, VS Code and the installed packages and extensions; the problem was from Git. To solve this problem, I changed the file name to a temporary name and also changed the places where it was used and then pushed the changes with git push. Then I changed the file name to the original name that I wanted and repeated the same path again and pushed the changes with git push and the error message was resolved.

Ruthi answered 28/1 at 23:56 Comment(0)
J
0

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

Jayme answered 6/7, 2018 at 15:8 Comment(0)
C
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.

Cateran answered 7/10, 2021 at 15:46 Comment(0)
G
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
Grimbal answered 28/6, 2022 at 11:23 Comment(0)
D
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.

Detestation answered 21/6, 2023 at 16:20 Comment(0)
B
0

I had 2 files that started with the same name

 |
 |-PcComponentCard.vue
 |-PcComponentCardList.vue

Fixed my problem by changing one of the names:

 |
 |-PcCard.vue
 |-PcComponentCardList.vue
Backboard answered 22/9, 2023 at 7:30 Comment(0)
S
0

For me the problem was that some folder higher in the folder structure (not the filename itself) was capitalized in Windows and everywhere it was referenced in my njsproj file but not in my import statements. I had to make those 3 sources consistent.

Sacramental answered 26/9, 2023 at 13:49 Comment(0)
D
0

React Js

Error :-

enter image description here

Resolve:-

You can try rename your file 'not component' to another name and once again

back to your original name.

Example:

consider we have a Register.jsx rename to RegisterForm.jsx

from

enter image description here

to

enter image description here

result

enter image description here

Dipsomaniac answered 29/10, 2023 at 11:54 Comment(0)
P
0

So weird bugs sometimes fixed by weird solutions.

If you don't have any error at all like the casing is accurate and you are still getting the error, what I did is remove the file and then restore it. The error disappear for me.

I don't know how it works but it works, maybe some vscode caching issues.

Edit: you should backup all the changes from that file first before deleting them especially if it's not committed yet.

Pitchblack answered 17/2 at 11:59 Comment(0)
C
0

For me, the problem was I was importing a component from an index.tsx file and thus omitting /index at the end of the file path in the import. I had, however, named the file Index.tsx instead of index.ts (accidental capital I in the filename) which caused this issue for me.

Renaming it from Index.tsx to index.tsx and restarting the IDE solved the issue for me.

Cockcrow answered 2/4 at 14:10 Comment(0)
R
0

Make sure all references to the file have been updated to the new casing. The error will persist until every single reference is updated.

Ripen answered 11/4 at 5:37 Comment(0)
N
0

Try restarting a language server like Vetur. In a local case, there was no text-case difference in source code or file-system, but the following error was still shown:

error

I have checked the "Problems" section in VS Code, and the error was coming from the mentioned Vetur. Restarting it solved the issue:

enter image description here

Ninfaningal answered 25/4 at 16:27 Comment(0)
C
-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.

Calvados answered 8/8, 2021 at 0:22 Comment(0)
L
-1

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

Loftus answered 21/12, 2022 at 1:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.