TypeScript: node_modules/@types cannot be deleted on Windows

Search Terms: is:issue is:open “visual studio”

Code npm run reset "reset": npx rimraf node_modules "devDependencies": { ...babel }

Expected behavior: node_modules files are deleted

Actual behavior: error: EPERM: operation not permitted… blah blah… node_modules/@babel/types/lib/index.js.flow

Related Issues: Exactly this issue (https://github.com/microsoft/TypeScript/issues/29407) but instead of VSCode it doesn’t work in VS2019 (16.1.3 on windows 10)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 24
  • Comments: 30 (9 by maintainers)

Most upvoted comments

Closing this so anyone who still faces issue can open new issue with concrete steps to repro and be able to investigate

Repro (for an angular project at least, extensions disabled):

ng new (accept all defaults)
open vscode
open main.ts so tsserver starts
npm ci
npm WARN prepare removing existing node_modules/ before installation
npm ERR! path D:\scratch\vscode-issue\node_modules\@angular-devkit\build-angular
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'D:\scratch\vscode-issue\node_modules\@angular-devkit\build-angular'
npm ERR!  [OperationalError: EPERM: operation not permitted, unlink 'D:\scratch\vscode-issue\node_modules\@angular-devkit\build-angular'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, unlink 'D:\scratch\vscode-issue\node_modules\@angular-devkit\build-angular'] {   
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'unlink',
npm ERR!     path: 'D:\\scratch\\vscode-issue\\node_modules\\@angular-devkit\\build-angular'
npm ERR!   },
npm ERR!   stack: "Error: EPERM: operation not permitted, unlink 'D:\\scratch\\vscode-issue\\node_modules\\@angular-devkit\\build-angular'",
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'D:\\scratch\\vscode-issue\\node_modules\\@angular-devkit\\build-angular'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
CPUs Intel® Core™ i7-7500U CPU @ 2.70GHz (4 x 2904)
GPU Status 2d_canvas: enabledflash_3d: enabledflash_stage3d: enabledflash_stage3d_baseline: enabledgpu_compositing: enabledmultiple_raster_threads: enabled_onnative_gpu_memory_buffers: disabled_softwareoop_rasterization: disabled_offprotected_video_decode: enabledrasterization: enabledskia_deferred_display_list: disabled_offskia_renderer: disabled_offsurface_synchronization: enabled_onvideo_decode: enabledviz_display_compositor: disabled_offwebgl: enabledwebgl2: enabled
Load (avg) undefined
Memory (System) 15.90GB (6.58GB free)
Process Argv –folder-uri file:///d%3A/git/PlatformWeb/ClientApp
Screen Reader no
VM 0%

Extensions: none

Windows 10 1903 Build 18362.207, but it also happens to my colleagues on 1809.

My setup and situation is the same as @Pike96 . VS Code/tsserver is holding lock on lots of my project’s source code files (which aren’t open in VS code editor tabs) and lots of \node_modules\ files. Restarting the tsserver is my work-around.

@biltongza I just ran exactly those steps without any problems

image

@RyanCavanaugh no action was taken to “fix” the old issue and I’m pretty sure it was ever fixed, just not verified correctly. https://github.com/microsoft/TypeScript/issues/29407 has 51 votes and should still be treated as your #2 voted bug.

We are running into this as well on our team. When we do a clean build, the build fails on a rimraf of one of our node_modules dirs. I’ve tried restarting the TS server and that doesn’t really help. SysInternals’ handle.exe shows the folder as locked by code.exe:

Code.exe           pid: 23548  type: File           508: C:\Users\hillr\Git\KLM\src\KalManagement\dist\kal-management\node_modules
Code.exe           pid: 23548  type: File           50C: C:\Users\hillr\Git\KLM\src\KalManagementAppServices\dist\kal-management-app-services\node_modules
Code.exe           pid: 23548  type: File           510: C:\Users\hillr\Git\KLM\src\KalManagementAppServices\node_modules
C:\Users\hillr
12-05 12:32:25 2> get-ntprocess 23548 | % CommandLine
"C:\Program Files\Microsoft VS Code\Code.exe" --max-old-space-size=3072 "c:\Program Files\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\tsserver.js" --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName C:\Users\hillr\AppData\Local\Temp\vscode-typescript\a046e5a7634361593230\tscancellation-2191af9d140a955dee64.tmp* --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation

But the command line shows that instance of code.exe is running the tsserver. This is driving our team crazy. Having to exit VSCode just to do a build is a PITA.

Have been tracking this issue for more than half a year, also have given up on VSCode for that long. Cannot believe that this is still a problem.

In my case, I have several local ts libraries that output to dist folder. My main app relies on those libraries, and also output to dist folder. There are .ts files in my libraries’ output files. So TS server in VSCode holds the files in dist, which prevent me from deleting dist folder before building the whole thing. If I disable typescript-language-features, then the problem is gone.

All related issues that I can found for my problem are closed and point to #29407 and this one.

#29407 was closed as an issue with electron, but this issue shows that there is another issue with the same symptoms since this one is about VS2019, which doesn’t use electron as far as I’m aware.

See also https://github.com/Microsoft/vscode/issues/72535. Pretty annoying to have to close the editor just to build Ng/TS projects, losing undo history. (Assuming it wasn’t fixed in TS 3.5 and is a TS issue rather than a VS or VS Code one…might be fixed in the Insider build, though!)