Typescript: File differs from already included file only in casing: correct casing but relative path

Created on 5 Jul 2018  ·  44Comments  ·  Source: microsoft/TypeScript

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?

It compiles just fine on Mac and Linux, but throws this error on Windows.

Bug Fix Available

Most helpful comment

I stumbled across this exact same error recently.
After doing some googling I found this. The last reply caught my eye. So I simply closed the folder is was working in in Visual Studio Code and re-opened it. After everything loaded up, no errors and I didn't have to mess with the tsconfig.json file.

hope this helps

All 44 comments

This looks like a bug, but we'll need some way to reproduce it. Do you have a zip file or repo or description of the files we could use?

As it turns out, the issue was with a third party module, tsify. Our project was using 1.0.1, and forceConsistentCasingInFileNames wasn't supported until 4.0.0.

I had same issue with one of my component import. I component directory name was historical with same "h" I was trying to import it with capital "H". It should be "
import { GraphDataComponent } from "./historical/graph-data/graph-data.component";" instead of "import { GraphDataComponent } from "./Historical/graph-data/graph-data.component" in app.moudule.ts.

Thanks @aaybhangu!

Hi, I am still facing this issue with - error TS1149: File name 'src/models/headers/userRole.ts' differs from already included file name 'src/models/headers/UserRole.ts' only in casing.
I have tried multiple ways to fix it , but no luck . I am using windows.

I am also facing the same issue.
For now, "solved" by setting:
"forceConsistentCasingInFileNames": false,
in tsconfig.json

I stumbled across this exact same error recently.
After doing some googling I found this. The last reply caught my eye. So I simply closed the folder is was working in in Visual Studio Code and re-opened it. After everything loaded up, no errors and I didn't have to mess with the tsconfig.json file.

hope this helps

I came across this same issue

  • remove the workspace didn't help
  • changing forceConsistentCasingInFileNames didn't help

For my case, somewhere in the directory, the errors were happening, was changed...? So I had to do the following to fix them all.

  1. You change the directory name to something like "OriginalDirectoryName" => "AnotherName"
  2. VsCode will try to update the directory name in the source, so wait for a few seconds, and it will show all the files need to be updated with the new directory name.
  3. Go File -> Save All and save them all
  4. Change the directory name back "AnotherName" => "OriginalDirectoryName"
  5. Again, it's gonna try to update files, so you save them all.
  6. Reboot VsCode.

then it should fix the problem.

I am getting this bug after renaming a file from the camelCase to uppercase all first letters

In my case, I used to create a file named Logger but changed to logger later. One file which imported this always shows this error message but actually in the terminal or other files, won't show this message.

So I use VSCode Reload Window feature to reload the VSCode, and the error message disappears. So I think maybe there is a cache somewhere in VSCode for this error and didn't clear? You can have a try if you face this problem after making sure the file name is correct.

I have the same issue, and just discovered that for some reason, in some ts file it is called using a capitalize letter, then I renamed it for lowercase and it works.

You can try also removing this model ts file and creating again with angular-CLI.

Changing case results in exception on updateOpen command. Note how file is opened with different case and closed with original casing in same command.

Info 69   [10:30:18.128] request:
    {"seq":5,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["c:/temp/est/Logger.ts"],"openFiles":[{"file":"c:/temp/est/logger.ts","fileContent":"export class logger {\r\n    \r\n}","scriptKindName":"TS","projectRootPath":"c:\\temp\\est"}]}}
Err 70    [10:30:18.153] Exception on executing command {"seq":5,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["c:/temp/est/Logger.ts"],"openFiles":[{"file":"c:/temp/est/logger.ts","fileContent":"export class logger {\r\n    \r\n}","scriptKindName":"TS","projectRootPath":"c:\\temp\\est"}]}}:

    Debug Failure. False expression: Script should not exist and not be open already

    Error: Debug Failure. False expression: Script should not exist and not be open already
        at ProjectService.applyChangesInOpenFiles (c:\Typescript\built\local\tsserver.js:138090:34)
        at Session.handlers.ts.createMapFromTemplate._a.(anonymous function) (c:\Typescript\built\local\tsserver.js:138972:46)
        at c:\Typescript\built\local\tsserver.js:140630:88
        at IOSession.Session.executeWithRequestId (c:\Typescript\built\local\tsserver.js:140621:28)
        at IOSession.Session.executeCommand (c:\Typescript\built\local\tsserver.js:140630:33)
        at IOSession.Session.onMessage (c:\Typescript\built\local\tsserver.js:140653:35)
        at Interface.<anonymous> (c:\Typescript\built\local\tsserver.js:141968:27)
        at Interface.emit (events.js:182:13)
        at Interface._onLine (readline.js:290:10)
        at Interface._normalWrite (readline.js:433:12)
        at Socket.ondata (readline.js:149:10)
        at Socket.emit (events.js:182:13)
        at addChunk (_stream_readable.js:283:12)
        at readableAddChunk (_stream_readable.js:264:11)
        at Socket.Readable.push (_stream_readable.js:219:10)
        at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

This issue seems to be more involved than just checking root file names. When reusing program there is another test case that fails which is simple program reuse test:

it("forceConsistentCasingInFileNames works when renaming file with different casing", () => {
            const loggerFile: File = {
                path: `${projectRoot}/logger.ts`,
                content: `export class logger { }`
            };
            const anotherFile: File = {
                path: `${projectRoot}/another.ts`,
                content: `import { logger } from "./logger"; new logger();`
            };
            const tsconfig: File = {
                path: `${projectRoot}/tsconfig.json`,
                content: JSON.stringify({
                    compilerOptions: { forceConsistentCasingInFileNames: true }
                })
            };

            const host = createWatchedSystem([loggerFile, anotherFile, tsconfig, libFile, tsconfig]);
            createWatchOfConfigFile(tsconfig.path, host);
            checkOutputErrorsInitial(host, emptyArray);
            host.writeFile(anotherFile.path, anotherFile.content.replace("./logger", "./Logger"));
            host.runQueuedTimeoutCallbacks();
            checkOutputErrorsIncremental(host, [
                createCompilerDiagnostic(Diagnostics.File_name_0_differs_from_already_included_file_name_1_only_in_casing, loggerFile.path, `${projectRoot}/Logger.ts`),
            ]); // Currently the errors are not reported in watch mode but will be reported if program is created from scratch.
        });

Yep, I'm having this same issue and none of the previously-stated fixes/workarounds do anything to help.

In my case, the message is:

error TS1149: File name '/mnt/c/Users/<username>/Documents/adobe-scripts/InDesign/Create Downloadable 
(2020a)/Illustrator/2015.3/index.d.ts' differs from already included file name '/mnt/c/Users/<username>/Documents/adobe-scripts/InDesign/Create Downloadable (2020a)/illustrator/2015.3/index.d.ts' only in casing.

@SturmB

Illustrator

and

illustrator

I'm well aware of the error message and what the transpiler sees. What I _don't_ understand is where it's getting the lowercase version of illustrator. I've done several searches and can find absolutely no instance where the word illustrator (when not used in a comment or string or whatever) is all lowercase. The one instance where I am referencing that index.d.ts file in that Illustrator folder, the word is capitalized properly, just as the directory name is.

I had a similar problem, but I can't reproduce it anymore. It seems like a VSCode bug: a file with uppercase name is displayed as a lowercase name in some cases, including the source control menu.

I've noticed that, sometimes, someone might change a folder's name from 'foo' to 'Foo' and when you do a git pull it either doesn't update the folder name, or someone forgot to push the change. In that case all your code references are correct, nothing in your code is wrong, and often times the files in that folder can be found just fine; it'll just make TS freak out.

So find the folder that's the root cause. Change the name of the folder. And commit that properly:

git mv foo tmp
git mv tmp Foo

Followed by commit and push would be the simplest way to rename a directory in a git repo.

Git has a configuration setting that tells it whether to be case sensitive or insensitive: core.ignorecase. To tell Git to be case-senstive, simply set this setting to false

See more:

https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git/17688308#17688308

what did it for me is undoing all renames, shutting down the server, renaming all the files I want to rename and restart the server. Must be some sort of caching issue.

Reloading window in VSCode fixed the issue. I changed a React component to camelCase and came across the issue. It does seem to be some sort of caching issue in VSCode.

I just came across this; my componentA.tsx imported ../store/someStore but this import resulted in this error, suggesting the filename was SomeStore.ts (even though the filesystem and VSCode show a someStore.ts at that location.

File name '/mypath/store/someStore.ts' differs from already included file name '/mypath/store/SomeStore.ts' only in casing. _ts(1149)_

Turns out some other file (../store/index.ts) had an incorrect import (./SomeStore) but did _not_ raise any error. After fixing that import and restarting VSCode, componentA.tsx no longer raises this error.

Reverting the fix to index.ts and restarting VSCode results in a spurious error on componentA.tsx again.

One thing I did to help my situation was to stop using WSL. I went back to my original custom setup which leverages Cygwin and I haven't had this issue since.

I am also facing the same issue.
For now, "solved" by setting:
"forceConsistentCasingInFileNames": false,
in tsconfig.json

Thanks, it helps

After doing some googling I found this. The last reply caught my eye. So I simply closed the folder is was working in in Visual Studio Code and re-opened it. After everything loaded up, no errors and I didn't have to mess with the tsconfig.json file.

This really worked

I was able to reproduce this by setting a name of a file and then renaming it to another. It doesn't appear to be updating in the source mapping properly. I deleted the problem file and added it again. A pain, yes, but it worked.

I had the issue, I fixed it by setting "forceConsistentCasingInFileNames": false
in tsconfig.json then to true again.

I fix it only reboot VSCode.

I have similar problem in WebStorm after changing file names, I'm quite sure it's some IDE cache.

If clearing cache/rebooting IDE don't help, remove folder, clone repo again and do clean install.

I've found this on a mac:

Scenario

  • file named ComponentA.ts
  • componentB.ts has import ComponentA from './ComponentA';
  • componentC.ts also has import ComponentA from './ComponentA';
  • change ComponentA.ts file name to componentA.ts
  • update componentC.ts to import ComponentA from './componentA;'
  • forget to update the import for componentB.ts so it still has the old capitalized import ComponentA from './ComponentA;'

Error (roughly):

 File name '/componentA.ts' differs from already included file name  '/ComponentA.ts'  only in casing. ts(1149)

Reason:

Case insensitivity on Mac is resolving the remnant import import ComponentA from './ComponentA;' in componentB.ts first, then 'caching/registering' this import path.

Then the correct import in componentC.ts is erroring even though it is correct.

How to Remedy:

  • find all imports of componentA.ts / ComponentA.ts
  • check case sensitivity and correct.

In my case, the erroring file componentC.ts was actually correct and I had to fix componentB.ts, even though the message was indicating an issue with componentC.ts.

I had to rename my file and gulp build. Then, I renamed back to the old original name and it builded fine.

Because of weird cache that doesn't cover case of changing name of vue file and thus complaining Vetur, I had to reload VS Code (Ctrl + Shirt + P -> Reload Window) as @uniquexiaobai advised.

A restart of the Typescript-Server will suffice. VSCode restart is overkill.

In VSC on OSX: CMD + Shift + P followed by typing TypeScript: Restart TS server.

With webstorm You need to invalide and clear the cache :
file > invalidate Caches/ restart

The shortest and best solution I found is.

Just remove that word from that causing casing problems.
e.g.
ListsDrawerOfContent and ListsDrawerofContent

I removed of from the file name. And the compilers compiled it correctly.

Then later I renamed by my desired case ListsDrawerOfContent.
Worked like a charm.

Also, keep in mind the git.

https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git

I had the same problem with import, after a rename a file from "a" to "A", i just restarted the vs code and then it works.

I had the same problem. VSCode restart and setting "forceConsistentCasingInFileNames": false can't help me.

error info:(just differ in disk symbol)
File name 'D:/mycode/devmono2/packages/server-sdk/index.ts' differs from already included file name 'd:/mycode/devmono2/packages/server-sdk/index.ts' only in casing.Vetur(1149)

why?

Solved!
Mine was a simple problem.

Everything was fine locally on mac, but i was getting this error on my Jenkins server. The problem was simply that locally the filename was 'quote.ts' but within my remote git repo it was 'Quote.ts'.

How the problem came about
So the filename was originally 'Quote.ts' which i pushed up. I then changed to 'quote.ts', but git did not see this as a change (I believe macs are case insensitive) - and therefore the case change was not reflected in remote repo.

And so when Jenkins pipeline ran, it was pulling down 'Quote.ts' when it was being referenced as '../../quote.ts' - which results in the error.

How i solved it

  1. Drink coffee
  2. Change filename in remote repo manually to be lowercase
  3. git pull locally
  4. Run pipeline

Boom Bam! Hope this helps someone

Had a similar issue that generated around 100 of these errors.

Didn't read them all to closely as they all seemed to have the same root problem. Had recently switched to running node in WSL2 that I took for granted was the cause of the issue. After 2 hours without success I actually went through the whole list and found one example where there was an actual bug.

import { FooInterface } from '../Foo'; // should be '../foo'
import { BarService } from '../Bar'; // should be '../bar'

I changed it to lowercase, reloaded vscode, rebuilt it and all the errors went away.

What I think happend is that ts tried to import the incorrect path ('Foo' instead of 'foo') and then cached the result and tried to use the incorrect cached path when processing the rest of the code.

Hopefully this helps someone out there!

i just restart my ide then the error is gone

just make a same object in component, and start your ng, after running successfully, then remove object and import your link,
then its should be work,
In my project it worked.

this just happened to me, it's an ongoing issue that hasn't been solved. It happens whenever I change the casing of a directory name and try to commit the change. Git doesn't recognize change in casing for a directory name.

+1......but WHYYYYYYYY

I just faced the problem. It turned out that when I tried to import it using vscode, VSCode used the previous file name and directory name. So I modified it and after running tsc it didn't show any error in the terminal, but I was still getting that read squiggly line in VSCode. So I restarted the Typescript server in vscode (Typescript: Restart TS Server) and it went away. Hope it helps someone.

@ninjavang you helped me! Had the same issue happening with my gitlab ci/cd pipeline. Turns out when i went to the remote branch and checked the file's path, there were two versions of the file, each in their case sensitive version.

I deleted the version unwanted on the remote, copied the file locally, pulled the remote down, refreshed my VS Code, and re-added the file. It worked!

Thanks for the help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dlaberge picture dlaberge  ·  3Comments

normalser picture normalser  ·  3Comments

RyanCavanaugh picture RyanCavanaugh  ·  3Comments

ggmod picture ggmod  ·  3Comments

kwpeters picture kwpeters  ·  3Comments