remix icon indicating copy to clipboard operation
remix copied to clipboard

Vite | Build | Client/SSR Duplicate Asset Error

Open PrescottJRynewicz opened this issue 10 months ago • 4 comments

Description

When migrating from esbuild to Vite, I encountered a small issue when creating the Vite production builds. Even though dev was working as expected, there was an error during the writeBundle step of the SSR build.

After debugging locally, I found a quick check that should resolve the issue I was facing.

Expected Behavior

Vite builds for production once the development server is working.

Actual Behavior

The client bundle builds appropriately, but the SSR bundle fails with this error

x Build failed in 2.07s
Error: [remix] dest already exists.
    at doRename (/workspaces/superbud-ecomm/node_modules/fs-extra/lib/move/move-sync.js:32:34)
    at Object.moveSync (/workspaces/superbud-ecomm/node_modules/fs-extra/lib/move/move-sync.js:17:10)
    at Object.handler (/workspaces/superbud-ecomm/node_modules/@remix-run/dev/dist/vite/plugin.js:875:28)
    at async Promise.all (index 0)
    at async PluginDriver.hookParallel (file:///workspaces/superbud-ecomm/node_modules/rollup/dist/es/shared/node-entry.js:19525:9)
    at async file:///workspaces/superbud-ecomm/node_modules/rollup/dist/es/shared/node-entry.js:20521:13
    at async catchUnfinishedHookActions (file:///workspaces/superbud-ecomm/node_modules/rollup/dist/es/shared/node-entry.js:19942:16)
    at async Module.build (file:///workspaces/superbud-ecomm/node_modules/vite/dist/node/chunks/dep-whKeNLxG.js:67445:22)
    at async viteBuild (/workspaces/superbud-ecomm/node_modules/@remix-run/dev/dist/vite/build.js:212:5)
    at async Promise.all (index 0)
    at async build (/workspaces/superbud-ecomm/node_modules/@remix-run/dev/dist/vite/build.js:245:3)
    at async Object.viteBuild (/workspaces/superbud-ecomm/node_modules/@remix-run/dev/dist/cli/commands.js:183:5)
    at async Object.run (/workspaces/superbud-ecomm/node_modules/@remix-run/dev/dist/cli/run.js:252:7) {
  code: 'PLUGIN_ERROR',
  plugin: 'remix',
  hook: 'writeBundle'
}

This error was thrown on writeBundle step, when a server asset was trying to be moved to the client asset directory, even though the client asset already existed.

Root Cause

This could also mean there is an issue with the getViteManifestAssetPaths or the clientViteManifest, because the manifest doesn't appear to have all the assets listed that actually exist in the assets folder.

Testing

I didn't see any tests for the plugin file, so I didn't include any here. This is also a two line change

PrescottJRynewicz avatar Apr 16 '24 02:04 PrescottJRynewicz

⚠️ No Changeset found

Latest commit: 065f7cb55690ac725d05e542d9a0f7460d9143eb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Apr 16 '24 02:04 changeset-bot[bot]

Hi @PrescottJRynewicz,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

remix-cla-bot[bot] avatar Apr 16 '24 02:04 remix-cla-bot[bot]

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

remix-cla-bot[bot] avatar Apr 16 '24 02:04 remix-cla-bot[bot]

If our logic is correct you shouldn't be seeing this error. Would you be able to share a minimal reproduction?

markdalgleish avatar Apr 16 '24 04:04 markdalgleish

Thanks for the quick response @markdalgleish. Yes - let me do a little more digging and whip something up.

PrescottJRynewicz avatar Apr 16 '24 16:04 PrescottJRynewicz

okay - @markdalgleish I added you to a stackblitz project with version of my branch where I am able to reproduce the error. https://stackblitz.com/edit/vitejs-vite-wdeefj

Dev will build and run but 404 without appropriate environment variables. Running npm run build should display the error I get.

Reproduction Steps

  1. Open stackblitz project
  2. Wait for startup procedures to complete.
  3. In the terminal, run npm run typecheck. This might fail due to sharp not being able to be installed in the web container. That is okay. This script also generates automated code that the project needs.
  4. In the terminal, run npm run build or npx remix vite:build

PrescottJRynewicz avatar Apr 16 '24 16:04 PrescottJRynewicz

@markdalgleish Ping to see if there are any updates.

PrescottJRynewicz avatar Apr 23 '24 17:04 PrescottJRynewicz

@PrescottJRynewicz Thanks for providing a repro. I was able to work out the root cause of this issue and fix it here: https://github.com/remix-run/remix/pull/9305

markdalgleish avatar Apr 24 '24 07:04 markdalgleish