Skip to content

Commit

Permalink
Fix dest already exists error during Vite build (#9305)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Apr 25, 2024
1 parent c53eb7d commit 5f144d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-planets-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Fix `dest already exists` error when running `remix vite:build`
9 changes: 7 additions & 2 deletions packages/remix-dev/vite/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ export const remixVitePlugin: RemixVitePlugin = (remixUserConfig = {}) => {
return JSON.parse(manifestContents) as Vite.Manifest;
};

let getViteManifestFilePaths = (viteManifest: Vite.Manifest): Set<string> => {
let filePaths = Object.values(viteManifest).map((chunk) => chunk.file);
return new Set(filePaths);
};

let getViteManifestAssetPaths = (
viteManifest: Vite.Manifest
): Set<string> => {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 5f144d5

Please sign in to comment.