Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite | Build | Client/SSR Duplicate Asset Error #9239

Conversation

PrescottJRynewicz
Copy link

@PrescottJRynewicz PrescottJRynewicz commented Apr 16, 2024

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

Copy link

changeset-bot bot commented Apr 16, 2024

⚠️ No Changeset found

Latest commit: 065f7cb

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Apr 16, 2024

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 hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Apr 16, 2024

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

@markdalgleish
Copy link
Member

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

@PrescottJRynewicz
Copy link
Author

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

@PrescottJRynewicz
Copy link
Author

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
Copy link
Author

@markdalgleish Ping to see if there are any updates.

@markdalgleish
Copy link
Member

@PrescottJRynewicz Thanks for providing a repro. I was able to work out the root cause of this issue and fix it here: #9305

Copy link
Member

@markdalgleish markdalgleish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this issue and for the PR! I'm closing this in favour of #9305 which has now been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants