Renaming files doesn't take effect in VScode while using WSL2

Viewed 75

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.

1 Answers

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?

Related