From b05c405f6884f9612fd8b6c1e7587a553cf58baf Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 5 Apr 2024 22:39:00 +0800 Subject: [PATCH] fix: `fsp.rm` removing files does not take effect (#16032) --- packages/vite/src/node/optimizer/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 4c98a289c5077a..43c0e22fd0140b 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -504,9 +504,12 @@ export function runOptimizeDeps( // No need to wait, we can clean up in the background because temp folders // are unique per run debug?.(colors.green(`removing cache dir ${processingCacheDir}`)) - fsp.rm(processingCacheDir, { recursive: true, force: true }).catch(() => { + try { + // When exiting the process, `fsp.rm` may not take effect, so we use `fs.rmSync` + fs.rmSync(processingCacheDir, { recursive: true, force: true }) + } catch (error) { // Ignore errors - }) + } } }