From 9818ff249aa49d62f44cde718cd4d66c7e0df9a3 Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Wed, 24 Apr 2024 17:07:10 +1000 Subject: [PATCH] Fix `dest already exists` error during Vite build --- .changeset/five-planets-grin.md | 5 +++++ packages/remix-dev/vite/plugin.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/five-planets-grin.md diff --git a/.changeset/five-planets-grin.md b/.changeset/five-planets-grin.md new file mode 100644 index 00000000000..d0657c90525 --- /dev/null +++ b/.changeset/five-planets-grin.md @@ -0,0 +1,5 @@ +--- +"@remix-run/dev": patch +--- + +Fix `dest already exists` error when running `remix vite:build` diff --git a/packages/remix-dev/vite/plugin.ts b/packages/remix-dev/vite/plugin.ts index 927322d97c0..ef3a54b4758 100644 --- a/packages/remix-dev/vite/plugin.ts +++ b/packages/remix-dev/vite/plugin.ts @@ -830,6 +830,11 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => { return JSON.parse(manifestContents) as Vite.Manifest; }; + let getViteManifestFilePaths = (viteManifest: Vite.Manifest): Set => { + let filePaths = Object.values(viteManifest).map((chunk) => chunk.file); + return new Set(filePaths); + }; + let getViteManifestAssetPaths = ( viteManifest: Vite.Manifest ): Set => { @@ -1401,7 +1406,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => { let ssrViteManifest = await loadViteManifest(serverBuildDirectory); let clientViteManifest = await loadViteManifest(clientBuildDirectory); - let clientAssetPaths = getViteManifestAssetPaths(clientViteManifest); + let clientFilePaths = getViteManifestFilePaths(clientViteManifest); let ssrAssetPaths = getViteManifestAssetPaths(ssrViteManifest); // We only move assets that aren't in the client build, otherwise we @@ -1413,7 +1418,7 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => { let movedAssetPaths: string[] = []; for (let ssrAssetPath of ssrAssetPaths) { let src = path.join(serverBuildDirectory, ssrAssetPath); - if (!clientAssetPaths.has(ssrAssetPath)) { + if (!clientFilePaths.has(ssrAssetPath)) { let dest = path.join(clientBuildDirectory, ssrAssetPath); await fse.move(src, dest); movedAssetPaths.push(dest);