Open yinxing-ws opened 1 year ago
I am not sure the issue here, but it sounds unlikely its a VS Code issue, rather an issue with your configuration. Maybe an Antivirus running?
I was having the same problem. I resolved it removing the VSCode User version and I installing the VSCode System version:
https://update.code.visualstudio.com/1.77.3/win32-x64/stable -> working https://update.code.visualstudio.com/1.77.3/win32-x64-user/stable -> with problem
I'm encountering this too when moving folders
For note, WebStorm doesn't have such problem
Is there a reliable reproduce or does it happen randomly?
@bpasero
Steps to reproduce
b.tsx
filea.tsx
a.tsx
c
folderI wonder if this issue is being caused by an installed extension. Can you try to run VS Code without extensions? From the command line (NOT the integrated terminal in Code), execute: code --disable-extensions
and try your steps again to see if it reproduces. If you see it is an issue with the extension, please file it against the extension repository itself.
@bpasero unfortunately it reproduces even without extensions
Hm, just to make sure, would it reproduce when you do the same with a txt
file instead of tsx
?
@bpasero I'll try
I tried .ts
and it didn't reproduce, only .tsx
Thanks, I suspect the typescript extension to install a watcher on dedicated folders that on Windows may result in folder locking.
Note regarding this portion of the initial post:
Steps to Reproduce: just rename or moving files/folder, and this problem occasionally. After restart vscode, the rename/moving operation completed automatically. I'm pretty sure the rename/moving operation act normally in file explorer
I tried the 3rd one while still having VSCode open without yet restarting it. Windows gave me the usual "File in use by another program" error. After restarting VSCode and closing all running commands, I was able to move the files/folders in Windows file explorer.
I also had this problem, but I found that setting typescript.tsserver.useSyntaxServer
to always
solved the problem. I guess there are too many files in the project directory.
This issue occurs for me as well, and has across a number of versions of vs code and typescript. It happens somewhat randomly. For example, I just moved a directory in an angular project without any issue, and this included dozens of nested directories and files. Then I tried to do the same thing with a different directory in the same project and it fails.
I checked the directory with a file lock utility and it shows that the directory is locked by a PID that appears to be the typescript language extension (tsserver.js).
Also, when this typically happens, I have been able to work around it by manually creating a new folder and moving all of the directory contents, as the lock is not on any of the actual typescript files.
I have the same problem on VSCode 1.83 with my NextJS project. Some folders are moving correctly but others can throw error. As soon as the TS server starts the folders are locked. If you move files and folders before the server starts, it will work. This pisses me off terribly and prevents me from refactoring the project. Because TS server gives the possibility to update imports automatically, without it you have to update them manually. I don't know who invented this. You can turn off all extensions, you can try the insider build, but it's all useless, the errors remain. I'm using latest Windows 11.
I have the same problem on VSCode 1.83 with my NextJS project. Some folders are moving correctly but others can throw error. As soon as the TS server starts the folders are locked. If you move files and folders before the server starts, it will work. This pisses me off terribly and prevents me from refactoring the project. Because TS server gives the possibility to update imports automatically, without it you have to update them manually. I don't know who invented this. You can turn off all extensions, you can try the insider build, but it's all useless, the errors remain. I'm using latest Windows 11.
I have the exact same experience
I have the same problem on VSCode 1.83 with my NextJS project. Some folders are moving correctly but others can throw error. As soon as the TS server starts the folders are locked. If you move files and folders before the server starts, it will work. This pisses me off terribly and prevents me from refactoring the project. Because TS server gives the possibility to update imports automatically, without it you have to update them manually. I don't know who invented this. You can turn off all extensions, you can try the insider build, but it's all useless, the errors remain. I'm using latest Windows 11.
I have the exact same experience
Same here
try in settings.json:
"typescript.tsserver.watchOptions": {
"watchFile": "fixedChunkSizePolling"
},
Adding these settings for tsServer didn't resolve problem for me. I can't rename files even if I just opened VSCode
I also had this problem, but I found that setting
typescript.tsserver.useSyntaxServer
toalways
solved the problem. I guess there are too many files in the project directory.
This unlocks the files but unfortunately it doesn't auto-update the imports.
The same issue here.
try in settings.json:
"typescript.tsserver.watchOptions": { "watchFile": "fixedChunkSizePolling" },
Works perfect, now I am able to rename or delete files/folders. But the drawback is that auto imports dont work anymore, But I can do it my self.... Thanks for the solution sir.
I have this issue too :(
This has been driving me nuts for months! I often have to close my VSCode to rename a directory in my project. I managed to create a minimum reproducible example on VSCode 1.88.0-insider with all extensions disabled.
.
└── main/
├── sub/
│ └── index.ts
└── main.ts
// content of main.ts
import { sub } from "./sub"; // IMPORTANT
// content of sub/index.ts
export const sub = () => true;
main.ts
file (IMPORTANT!, I suspect this triggers the TS file watcher)main
folder to something else. It won't work because of the directory lock.Seems like the import
on main.ts
has something to do with the locking. If you delete / comment the import line, reopen VSCode / reload window, then repeat the 3rd and 4th steps, the directory renaming will work just fine.
I did try moving the sub file to the same directory as the main file like this:
.
└── main/
├── sub.ts
└── main.ts
and the directory renaming works fine too, so I guess it only happens when you are importing a file from a subdirectory? 🤷🏻♂️
@bpasero maybe that could help.
Time goes by and the problem is still relevant. The only thing I found to avoid restarting VSCode every time is to go to the TypeScript file and open Command Palette and find "TypeScript: Restart TS Server", this option will not appear if your cursor is not focused on the TypeScript file. And while it is restarting you can rename your file or folder, but if it restarts before you rename it will lock your files or folder again and of course there will be no automatic import update. :D
Just bumped into this issue. Is there a way to rename folder while auto updating imports without using VSCode? Any command line tools for this?
I've been running into this issue for months. I've kept having to close out of VSCode any time I wanted to do something to a directory that contains sub-directors (when it's just files, it seems to work most of the time). After a lot of searching for solutions over the past couple months, I finally stumbled on this older issue today: https://github.com/microsoft/TypeScript/issues/7762, which ultimately lead me here. Sure enough, restarting the TS Server gets rid of the issue temporarily.
👋 we are experimenting with using VS Codes core file watcher in the TypeScript extension (https://github.com/microsoft/vscode/issues/208872). There is a new setting typescript.tsserver.experimental.useVsCodeWatcher
available starting with todays VS Code insider release. Curious if people could try it out by enabling it and seeing if the EPERM
issue gets better. In my testing https://github.com/microsoft/TypeScript/issues/54087#issuecomment-2028554228 seems to be resolved at least.
It is worth noting that this is a change that may come with other bugs and we are happy for feedback and early adopters 🙏 . Please report issues at https://github.com/microsoft/vscode/issues
You can give our preview releases a try from: https://code.visualstudio.com/insiders/
👋 we are experimenting with using VS Codes core file watcher in the TypeScript extension (microsoft/vscode#208872). There is a new setting
typescript.tsserver.experimental.useVsCodeWatcher
available starting with todays VS Code insider release. Curious if people could try it out by enabling it and seeing if theEPERM
issue gets better. In my testing [#54087 (comment)]
Latest Windows 11. Latest VSCode Insiders. With TypeScript Nightly or without it. Project based on Nx, TypeScript, ReactJS, NextJS. Same result.
@SuspiciousLookingOwl i followed exact steps with latest typescript build on vscode insiders (without the experimental setting) as well as vscode
with typescript nightly . I am on windows and there seems to be no issue in renaming. Which OS are you on? Please share your tsserver.log file so we can see what all its watching and see if we can figure this out. So far we just have reports of this without actually being able to repro this locally and thats not helping fix the issue.
@sheetalkamat I'm on Windows, but you are right! I tried my steps again, and the renaming works. I swear it wasn't working last time 😅 I'll see if I can find a way to reproduce it consistently.
EDIT: I did an update on my VSCode Insider recently though, so maybe that fixes it like what @bpasero has mentioned? Now I'm not sure whether my minimum reproducible example actually did break the file renaming or if I just misconfigured my VSCode.
To clarify, typescript.tsserver.experimental.useVsCodeWatcher
is not enabled by default, so you need to change settings as well as being on latest.
I just tested renaming a directory which has many subdirectories with many files and it failed just like it's been failing.
I tested with the typescript.tsserver.experimental.useVsCodeWatcher
enabled and not and both way failed while running a nextjs (v12.3.1)
project.
Version: 1.89.0-insider (user setup) Commit: 50a6f4f200c5a33f47997eb6a8966e50cf219e21 Date: 2024-04-12T05:50:19.038Z Electron: 28.2.8 ElectronBuildId: 27744544 Chromium: 120.0.6099.291 Node.js: 18.18.2 V8: 12.0.267.19-electron.0 OS: Windows_NT x64 10.0.19045
Componentss
directory):But using PowerToys File Locksmith it says that the directory is being held by node.exe
Can you do this and share the contents of the File Watcher
output channel:
Does this issue occur when all extensions are disabled?: Yes/No
VS Code Version: Version: 1.77.3 (user setup) Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710 Date: 2023-04-12T09:16:02.548Z Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Windows_NT x64 10.0.19044 Sandboxed: No
OS Version: Windows 10 professional
Steps to Reproduce:
I have checked all below items, so I'm pretty sure there is no other process using these files except vs code.