3

I'm getting compile errors on many of my files. One issue seems to be that running my package.json script: "react-scripts start" causes errors where I have two files in the same location with similar names.

For example when I have two files in the same location: src\Context\GlobalContext\globalContext.ts

src\Context\GlobalContext\GlobalContext.tsx

And I try to import the GlobalContext.tsx file, the compiler seems to be ignoring my GlobalContext.tsx file and looking in globalContext.ts.

Compiled with problems:X

ERROR in ./src/App.tsx 14:0-66

Module not found: Error: Cannot find file: 'GlobalContext.ts' does not match the corresponding name on disk: '.\src\Context\GlobalContext\globalContext.ts'.

...

src\App.tsx
  Line 9:27:   Casing of ./Context/GlobalContext/GlobalContext does not match the underlying filesystem  import/no-unresolved
  Line 10:25:  Casing of ./Context/UserContext/UserContext does not match the underlying filesystem      import/no-unresolved

It seems to work both ways though. This error suggests that the compiler is looking at a SearchContext.tsx file when it should be looking at a searchContext.ts file. The compiler seems to be ignoring the 'x' in the .tsx and getting very confused:

TS1149: File name 'C:/../src/Context/SearchContext/searchContext.ts'
differs from already included file name
'C:/.../src/Context/SearchContext/SearchContext.ts'
only in casing.

This has never been a problem on Linux, and wasn't previously a problem on my Windows OS until today. I also appear to be having similar issues with my Node/Express server. I installed ts-node

I have tried:

  1. Reloading my VS Code
  2. Restarting my machine
  3. Toggling my tsconfig.ts compilerOptions: "forceConsistentCasingInFileNames": false
  4. Clearing my VS Code cache (all above solutions from this thread)
  5. Restart the typescript server: opening the Command Palette (Ctrl+Shift+P) --> Select Typescript: Restart TS
  6. Removing my VS code workspace (as per this suggestion)
  7. Renaming files fixes the issue. For example, changing GlobalContext.tsx to GlobalContextProvider.tsx in both the import statement and the file name prevents the error.
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71

1 Answers1

3

It looks like my issue is discussed in this blog post: https://briandesousa.net/?p=870 and also in this github thread https://github.com/Microsoft/TypeScript/issues/21736

I'd been working previously on Linux, which imports with case sensitivity, whereas Windows and MacOS don't. So where I have two files of the same name but with different cases, Windows can't tell the difference - even when the have different .ts/.tsx extensions.

It seems that the tsconfig.ts compilerOptions: "forceConsistentCasingInFileNames": true setting, simply provides warnings when there are inconsistent casings, it doesn't actually fix anything.

There doesn't seem to be a simple way to get Windows to distinguish by case sensitivity so the solution is to rename all of my similar files.

JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71