166

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.

3
  • In my case it was the case, (used uppercase instead of lower case)
    – 27px
    Dec 31, 2020 at 11:25
  • 2
    Simply restarting VSCode fixed the issue for me. Could be a weird IDE bug.
    – OGreeni
    Jan 8 at 15:40
  • 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.
    – TTT
    Mar 20 at 17:30

22 Answers 22

193

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.

7
  • 15
    Usually for stuff like this Reload Window works for me, but in this case a full restart of VS Code was needed
    – Jack Barry
    Mar 5, 2021 at 17:55
  • 6
    I had to do a full restart
    – SujithaW
    Jul 30, 2021 at 14:23
  • 2
    Same... Restarting did the trick Dec 21, 2021 at 15:44
  • 2
    I did the same thing as op, but for Vetur, it does not go away even after I restart vscode
    – Darky WC
    Apr 27, 2022 at 3:08
  • it's work fo me, tnx
    – al.koval
    May 5, 2022 at 7:46
104

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';
3
  • 2
    This answer is the correct one. Sep 26, 2021 at 8:40
  • thats the one. thanks Oct 10, 2021 at 15:01
  • 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 Feb 1 at 15:38
93

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.

11
  • 6
    You're literally my hero. Thank you! Jul 21, 2021 at 12:21
  • 2
    @novonimo, You're my hero too, thanks bro!
    – AmerllicA
    Oct 16, 2021 at 16:18
  • 2
    Yep it works thanks HERO LOL
    – zt1983811
    Jan 24, 2022 at 2:55
  • 1
    What I've just discovered, removing extension in component import statement also helps. Can't figure it out why, yet. Apr 1, 2022 at 5:37
  • 2
    I did the solution similarly as op, but just reload my vscode after renaming the file. Then revert its name after reload, and it works for Vetur.
    – Darky WC
    Apr 27, 2022 at 3:13
53

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

So you should have something like that:

{
  "compilerOptions": {
    ...
    "forceConsistentCasingInFileNames": false,
    ...
  }
}
2
  • 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, 2021 at 21:24
  • I tried fully restarting VSCode but the problem persisted. Changing this config setting to false instantly fixed it, though it's worth mentioning that if you actually wanted this setting you'd still be in a pickle.
    – Ali
    Nov 23, 2022 at 4:24
35

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

4
  • 4
    In my case I just renamed the file then renamed it back again
    – Fabricio
    Mar 13, 2021 at 21:51
  • Same here, renaming the file and then make it back again worked for me as well. tnx Aug 2, 2021 at 12:42
  • Same, renaming the file. Weird issue.
    – Danny
    Sep 14, 2021 at 21:24
  • In my case it was ComponentName.Vue vs. ComponentName.vue (upper and lower case V). Everything appeared lowercase as intended but still the error. The steps above worked. Thanks Nov 9, 2021 at 19:29
32

For VS Code IDE users:

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

0
13

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

2
  • 1
    in case anyone else has the same problem in Vue, I can vouch this solves the error, at least in Vue3. Oct 10, 2020 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. Sep 7, 2021 at 17:42
6

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

2
  • 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 3, 2020 at 20:46
  • 1
    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, 2020 at 23:04
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

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.
0
2

For me the problem only went away:

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

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

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.

0

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

Incorrect:

import React from "React";

Correct:

import React from "react";
0

Writing the import again worked for me.

0

Remove .vue extension and it worked

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.

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.

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
0

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

1
  • it says no files to commit Dec 27, 2022 at 20:07
0

For Visual Stuido Code user, Restart TS Server fixed my issue without rebooting the whole 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.

2
  • 10
    what is tisfy ?
    – kkost
    Sep 8, 2018 at 23:36
  • 7
    Updating what? please provide more info on what you updated
    – katwekibs
    Jan 19, 2020 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.