3

I have a very annoying problem in my VScode setup.

I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.

For example:

I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.

Cant open file because not found

Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.

So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.

The file is there in my folder but when I click on it, I get

"Unable to open Mainheader.js - File not found"

So I try to create it then I get this error:

Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set

Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...

Any help would be appreciated. I can't really work like this.

Paul Marmagne
  • 153
  • 10

2 Answers2

0

I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.

I did find this work-around though:

  1. Open a new VS Code window. (I'd recommend closing any VS Code window that had your project directory open.)
  2. Create a duplicate or copy the contents of the problem file so you don't lose your code.
  3. Delete the problem file.
  4. Now create the file again using VS Code. Go to File > New Text File. Next paste in your code.
  5. Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
  6. Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.

Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.

Hope this work-around works for you!

EDIT 09/20/2022 Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.

How to run VScode in sudo mode in WSL2?

ebonzo
  • 1
  • 2
0

You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.

Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.

My default config looked like this yours may be different:

[automount]
options = "metadata"

add

[automount]
options = "metadata,case=dir" 

Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config