This problem had me frustrated for a considerable amount of time, but I managed to find a solution while working on my current project. (Remounting the WSL root didn't resolve the issue for me, unfortunately.) The symptoms I experienced were slightly different from those mentioned in the original question, but I hope that sharing what I discovered may offer some valuable insight.
In my case, the issue stemmed from a combination of factors and only occurred when attempting to run react-scripts start
for a specific project. What puzzled me was that I had another project within WSL with an almost identical setup that ran smoothly without any issues.
After extensive investigation, I identified the root cause as the case-sensitive-paths-webpack-plugin used internally by react-scripts
. By strategically inserting several console.log()
statements in the fileExistsWithCase method, I was able to pinpoint where the problem lied.
The function is responsible for checking whether a file or directory on disk matches the given string (filepath
) in terms of casing. To achieve this, it recursively traverses each directory in the path. Unfortunately, there appears to be an issue with error logging. When an error propagates through the recursion loops, it mistakenly appends the name of the problematic folder as if it were the original filename (I reported this as an issue in the create-react-app repository).
For instance, the error message from the initial question stated:
Cannot find file: 'index.js' does not match the corresponding name on disk: '/mnt/c/users/<my_username>/Projects/test_module/Users'.
In this scenario, after several recursions, the library listed all contents in /mnt/c
, and upon noticing that the directory users
did not exist but Users
did, the error surfaced incorrectly citing
/mnt/c/users/<my_username>/Projects/test_module/Users
.
During file or directory checks, the library first investigates its cache and preloads the cache with the current working directory for reference. This discrepancy explained why one project worked while the other failed. The successful project utilized npm, with its node_modules structured as $PWD/node_modules/foo
, which halted recursive searches once reaching $PWD
. Conversely, the failing project employed pnpm, hoisting dependencies to a higher level. In my scenario, validation errors occurred when verifying the directory /mnt/c/Users/[username]/wslhome
, erroneously perceived as WSLHome
on disk.
I resorted to renaming WSLHome
to wslhome
, enabling functionality in my project. Regrettably, renaming /mnt/c/Users
posed challenges since Windows created it.
Essentially, the issue seemed linked to how the package's dependencies' absolute paths were defined and whether their casings coincided with Node's path
interpretations.
UPDATE: Recently, upon revisiting the project, I encountered failures again, this time complaining about inaccurate casing in the "Users" directory. To rectify this, I stumbled upon an article regarding enhancing case sensitivity options when accessing Windows directories. After incorporating case=dir
into my wsl.conf preferences and restarting the subsystem, the error vanished. However, due to its erratic nature, I cannot definitively confirm it as the resolution.
An additional potentially relevant observation involves inconsistencies seen when executing readlink -f
on a dependency directory. Sometimes, outcomes reflect accurate casings, while other times they do not. For example, currently, readlink -f ~/dev
inaccurately returns a subdirectory of /mnt/c/users
, whereas readlink -f .
correctly illustrates a subdirectory of /mnt/c/Users
when within the ~/dev
directory.