I've been encountering compile errors in several of my files. One particular issue arises when I run the script in my package.json
: "react-scripts start", causing errors when two files with similar names are located in the same directory.
For instance, having both of these files in the same location:
src\Context\GlobalContext\globalContext.ts
src\Context\GlobalContext\GlobalContext.tsx
When attempting to import the GlobalContext.tsx
file, the compiler appears to be ignoring it and searching for 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
The problem seems to go both ways. The error suggests that the compiler is looking for a SearchContext.tsx
file instead of a searchContext.ts
file. It doesn't seem to recognize the 'x' in .tsx
, leading to confusion:
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 was never an issue on Linux and only recently became problematic on my Windows OS. Similar issues are also occurring with my Node/Express server. I installed ts-node
Steps I have taken to address this include:
- Reloading VS Code
- Restarting my computer
- Toggling
tsconfig.ts
compilerOptions
:"forceConsistentCasingInFileNames": false
- Clearing the VS Code cache (all above solutions from this thread)
- Restart the typescript server: opening the Command Palette (Ctrl+Shift+P) --> Select
Typescript: Restart TS
- Removing my VS code workspace (as per this suggestion)
- Changing file names resolves the issue. For example, renaming
GlobalContext.tsx
toGlobalContextProvider.tsx
in both the import statement and the file name prevents the error.