remix
remix copied to clipboard
Vite | Build | Client/SSR Duplicate Asset Error
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
⚠️ 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
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
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳
If our logic is correct you shouldn't be seeing this error. Would you be able to share a minimal reproduction?
Thanks for the quick response @markdalgleish. Yes - let me do a little more digging and whip something up.
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
- Open stackblitz project
- Wait for startup procedures to complete.
- In the terminal, run
npm run typecheck
. This might fail due tosharp
not being able to be installed in the web container. That is okay. This script also generates automated code that the project needs. - In the terminal, run
npm run build
ornpx remix vite:build
@markdalgleish Ping to see if there are any updates.
@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