TypeScript
TypeScript copied to clipboard
TypeScript file watcher holds onto folders and causes EPERM
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:
- 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 have checked all below items, so I'm pretty sure there is no other process using these files except vs code.
- no other window opened.
- no vscode extension runing because I uninstall them all.
- only vscode using the file, It's weird because there are two records.
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
https://code.visualstudio.com/updates/v1_77
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
- Create such project structure
- Double click
b.tsx
file - Click
a.tsx
- Close
a.tsx
- Try renaming
c
folder
https://user-images.githubusercontent.com/18424848/235309581-be1487f0-81c2-472f-9f47-d3be545649af.mp4
I 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
https://user-images.githubusercontent.com/18424848/235316327-61a0f285-f702-4f54-a13d-29469cc83c98.mp4
Hm, just to make sure, would it reproduce when you do the same with a txt
file instead of tsx
?
@bpasero I'll try
no it doesn't reproduce
https://user-images.githubusercontent.com/18424848/235316603-a23aaed1-7be1-4c5b-809f-a33f1357f4e6.mp4
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.
- Create a project folder with this structure
.
└── main/
├── sub/
│ └── index.ts
└── main.ts
// content of main.ts
import { sub } from "./sub"; // IMPORTANT
// content of sub/index.ts
export const sub = () => true;
- Open the project folder in VSCode
- Open the
main.ts
file (IMPORTANT!, I suspect this triggers the TS file watcher) - Try renaming the
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.