VS Code unable to rename folder on Windows 10. I get "Error: EPERM: operation not permitted, rename..."
Asked Answered
S

16

23

Problem:

VS Code is unable to rename folders in JavaScript projects when this folder contains a file with an 'import' statement that imports a file from a subfolder.

Since this is a very common situation in js projects, this has become a very frequent problem.

When the issue manifests itself, I get the error:

Error: EPERM: operation not permitted, rename 'd:\project\parentFolder' -> 'd:\project\newName'

How to Make the Issue Manifest Itself:

The Setup:

Inside an empty project,

  • Create a folder (parentFolder)
  • Create a .js file inside the folder (parentFile.js)
  • Create a subfolder inside the folder (childFolder)
  • Create a .js file inside the subfolder (childFile.js)
  • Import the child file from the parent file using JavaScript import statement

enter image description here

Getting the Issue

  • Open the parentFile.js in VS Code
  • Try to rename the parent folder

VS Code will hang, the bottom bar will say it's trying to rename the file, and after a while, the file won't be renamed and I get the error stated above.

If VS Code is reloaded and the parentFile.js is kept closed, the issue won't appear. But if it was opened once, even if the file is closed before renaming it, the issue will appear.

Relevant Info:

  • Windows 10 (Dell Precision M6700)
  • VS Code version 1.74.2 x64 (I tried both 'user' and 'system' install options)
  • I tested removing all extensions and settings from VS Code
  • I tested removing node.js from my machine
  • I formatted my machine recently. I was having this issue before and I continue to have it after

Edit:

  • I formatted my PC again, installed VS Code right away (and no other program) but the problem persists.
  • I tried it on a different PC (win 10, Dell), and had the same issue.
Sacttler answered 24/12, 2022 at 21:38 Comment(7)
I cannot reproduce this problem - works fine for me following your steps.Flunky
@topsail, this might be a tricky one. VS Code bugging with only a simple import statement is (to me) an indication that the problem might be in my machine...Sacttler
I am having the same issue. It's happening on a new laptop with Windows 11 pro. It wasn't happening on my older laptop with Windows 10 pro. @LucasChammaNahas has this been resolved?Betel
@ghd, no I haven't found a solution to this problemSacttler
Open Vscode as admin - The solution worked for meLurette
Does this answer your question? VS Code - Error: EPERM: operation not permittedSterilize
run vscode as administrator?Ismaelisman
C
14

I had the same issue and found out that the solution is to stop the development server before renaming the folders.

Chukker answered 19/7, 2023 at 9:10 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jocasta
@Jocasta I disagree. This problem is just too specific for being documented anywhere. Let alone the fact that this answer is very helpful.Spies
P
4

best way is using other code editors

like : press ctrl + shift + p and type reload window

then rename it

Piave answered 7/1 at 14:47 Comment(0)
O
3

Close all tab of project in VS Code (or another IDE same). Then you can rename this.
Hope this help you.

Close all - Context Menu

Oxide answered 29/9, 2023 at 1:52 Comment(1)
This is what worked for me. If you have a file open in the project and try to rename the folder that it's in, you'll get the error.Chippy
E
3

The problem for me was the extension called "Live Server" by "Ritwick Dey". Disabling that fixed the issue for me. I hope it helps

Expeller answered 6/11, 2023 at 5:5 Comment(1)
After doing this happens sometimes. but turning off the node server fixes it.Expeller
D
3

I had this exact problem. What worked for me is changing the name in the file explorer rather than vscode. Give it a go!

Dicotyledon answered 10/1 at 7:9 Comment(1)
Only an option which helped me, thank youIberian
H
2

I've found that in my case the problem is caused, because VS code marks the open project (folder) as being used, and hence cannot by modified by other programs or processes. But for some reason the VS code renaming process is being stopped by this feature.

Holna answered 20/7, 2023 at 9:28 Comment(0)
B
1

try to remove .vscode(it's a hidden folder so show hidden items first) folder if exists if this didn't help check this question

Beaufert answered 25/12, 2022 at 17:24 Comment(1)
Unfortunately, deleting .vscode does not work... I even tried a completely fresh installation of VS Code, with no luck... Regarding the question you sent, they don't seem to have solved it either... Although the issue seems to be exactly the sameSacttler
C
0

I encountered a similar issue, and in my case, it was caused by a VSCode extension, specifically the Live Server extension. Disabling this extension resolved the problem for me. If you don't have Live Server installed, consider checking other VSCode extensions. Additionally, make sure to stop any local servers.

Cheyennecheyne answered 1/12, 2023 at 17:49 Comment(0)
E
0

you just need to stop the server and then you rename the folder.

Eviaevict answered 7/12, 2023 at 19:51 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Jocasta
S
0

In my case, close all tabs and close all terminal does the job. Just make sure no activity is running or tab opened.

Shoplifter answered 16/12, 2023 at 15:37 Comment(0)
C
0

Disable the wsl extension if you are on windows.

Clap answered 10/2 at 3:28 Comment(0)
C
0

My problem got fixed but updating my vscode going to help -> install update, then restarting the IDE after the update finished.

Chequerboard answered 9/3 at 2:39 Comment(0)
P
0

Faced this issue in Next Js and I figured out that you have to stop the dev server in order to rename the folder. There are no docs available to prove my point but I believe Next JS handles routes with the folder name. As routes are determined based on the names of the folders so, you have to stop the dev server as the folder names became routes when you run the application.

Paternalism answered 24/4 at 21:50 Comment(0)
C
0

Ive been having the same issue for a while now as well.

For me -> the only work around that seems to work every time (besides doing it from file explorer outside of vscode is to Close the window as the progress bar is still ticking on the bottom right of the window. This is before the error is triggered.

Upon doing this, it is the desired name when I reopen vscode.

again just a workaround as its very annoying to have to close everything down inorder to rename something.

Cacography answered 4/5 at 17:7 Comment(0)
M
0

What you need to do is to stop debuggger, rename folder and start debugger again, tested in July 2024 VSCode version 1.91 (latest)

Meissen answered 9/7 at 9:35 Comment(0)
A
0

Stopping the terminal from running the project and reloading VS Code has worked for me.

Use Ctrl+Shift+P and select 'Reload Window'.

Arndt answered 12/7 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.