My vsc code disappeared and I have no idea why or where it's gone
Asked Answered
P

4

11

I was working with discord.js last night and I ran a few commands in the terminal. The last command I wrote caused the name of the file at the top of the screen to be crossed out and turn red and I followed the path to where the file was and it was gone. I've checked the recycling bin and nothing was there. The file has left no traces and the project is gone. Is there any way that I can get the code back?

The commands I ran were -

npm update, 
npm audit, 
npm audit fix (the one that caused the file to disappear)

My file was also within the node_modules folder which probably explains why it disappeared when I ran those.

Any help is appreciated, thanks.

Palocz answered 23/1, 2022 at 10:5 Comment(0)
R
18

Yes, apparently this happens sometimes, especially when there is update on restart (see here https://github.com/microsoft/vscode/issues/52855). For some reason the software is moved to

C:\Users\<user>\AppData\Local\Programs\Microsoft VS Code\_

where <user> is your username. If you start from there it goes as always. I didn't try any move or rename, just reinstalled the last version and everything went back to normal. This is first time happening to me, and according to most reports it doesn't happen often enough to be a problem, however a few users report it to have happened tens of time, that I understand being an annoyance.

EDIT: after two months from this answer, I have been experiencing the problem more and more often. What I noticed is that the problem seems to be originated by a failed automatic update, possibly in coincidence with some memory failure. It seems that an update is started, but then the program fails to complete it by moving files from temporary folder. SOLUTION: just run an update after the failure, you will get some issue with Ripgrep (rg.exe), ignore them and the software will be restored. Also, I have found this thread Visual Studio Code updating woes, where it is suggested to disable option update.enableWindowsBackgroundUpdates. I am giving it a try.

UPDATE: about four months after last edit, I can say it never happened again, at the point I even had forgotten the issue (there were some crashes during install due to other reason, but differently from before, they didn't make VScode disappear). Of course I cannot be sure if it was disabling the option, or a VScode updates which fixed the problem, but if you are experiencing this issue, I suggest you give it a try.

Roundy answered 12/12, 2022 at 21:46 Comment(4)
Thanks you helped me find out that my VS Code had gone in _. That's pure magic!Ridiculous
So this happened with my installation today, and it seems to be in the "_" folder. now are you suggesting that I download and install the latest version to fix it ? I want to keep all my settings and dev environment as it was. Please advise. Thanks.Generalization
yes, I did it several times and everything goes back in place. However there was an instance in which I had lost my environments. I don't know if it was because I had tried to do some manipulation instead of just reinstalling, but I suggest to backup the environments (which it might always be useful), for example like in #44112957Roundy
I use venv and everything is back in place after installing the latest version from the official downloads page.Domestic
X
0

If the file that got removed was inside the node_modules folder there's no problem. You can just remove the node_modules folder and run npm install . That will fix the problem.

If there is not package.json file in your project, you can still remove the node_modules folder but then you need to install every dependency manually like this: npm install <module_name>.

Xena answered 23/1, 2022 at 12:25 Comment(4)
I really don't know if I'm doing this right. I ran npx rimraf node_modules and then npm install in the terminal and nothing appeared. Is that the wrong line of commands to run or is there somewhere specific I should be looking for a result?Palocz
Before running npm install you need to delete the node_modules folderXena
Okay, I saw what I did wrong when I followed those steps the first time so my bad. I removed the folder, ran the command and the folder came back, but the file is still gone. Do you have any idea what npm audit fix does and why it caused the file to disappear?Palocz
Okay, I know why the file disappeared. Do you know where the removed node_modules folders go? Are they anywhere on my computer or are they permanently deleted?Palocz
C
0

Happens to me a lot when running tests in the Test Explorer.

To get your code back: Right click on the project in the solution explorer. From the Menu select: Open Folder in File Explorer. Open any file in one of the folders. Add a comment Ex) // Test. Save the file. Restart VS. You should have your code back.

I can't believe MS doesn't consider this a big enough problem to address.

Cusped answered 17/10, 2023 at 17:53 Comment(0)
J
0

My vscode dissapeared too when I opened my PC. I saw when I was shutting it down some vs code updates were in progress. However, the PC shutdown and after reopening the PC, vscode dissapeared. Either you will find it on the path: C:\Users\abdul\AppData\Local\Programs\Microsoft VS Code. If you don't find it there, checkout this path (folder inside the previous path): C:\Users\abdul\AppData\Local\Programs\Microsoft VS Code\_.

Javelin answered 8/9, 2024 at 11:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.