Skip to content

fix(bundle): read vite build output after buildApp resolves - #795

Merged
john-royal merged 2 commits into
mainfrom
john/vite-environment-no-build-app
Jul 9, 2026
Merged

john-royal merged 2 commits into
mainfrom
john/vite-environment-no-build-app

Conversation

@john-royal

@john-royal john-royal commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

On Vite 8, builder.buildApp() runs post-order buildApp hooks before the default environment builds when a project declares no builder.buildApp (e.g. a plain client-only SPA, which resolves as appType: "spa"). Our alchemy:build-output plugin resolved the build output from a post-order buildApp hook, so it fired while the client/server output was still empty and viteBuild died with "neither assets nor server output" (#792).

viteBuild already awaits builder.buildApp() before reading output, so instead of resolving from a plugin hook, the plugin just collects state in writeBundle and exposes output as a lazy read. By the time viteBuild awaits it, every environment that actually built has run writeBundle.

-    buildApp: {
-      order: "post",
-      async handler() {
-        Deferred.doneUnsafe(deferred, Effect.succeed({ clientDirectory, serverBundle: makeServerBundle() }));
-      },
-    },
+    async writeBundle(_, bundle) {
+      // ...record clientDirectory / server chunks...
+    },
   return {
     plugin,
-    output: Deferred.await(deferred),
+    // Only safe to await *after* `builder.buildApp()` has resolved.
+    output: Effect.sync((): ViteBuildOutput => ({
+      clientDirectory,
+      serverBundle: makeServerBundle(),
+    })),
   };

This also avoids the trap of tracking "all registered environments built": a client-only SPA falls back to Vite's legacy single-environment builder, which only builds the client environment — the registered ssr environment never builds, so waiting on its writeBundle would hang forever.

Test

Adds the world's simplest Vite fixture (vite-spa-fixture: a client-only app, no config, no plugins) and a deploy test exercising the appType: "spa" path from #792.

Fixes #792

On Vite 8, `builder.buildApp()` runs post-order `buildApp` hooks before
the default environment builds when the config declares no
`builder.buildApp`, so the hook resolved the build output while it was
still undefined and `viteBuild` saw neither assets nor server bundle.

Track each environment in `configResolved`, mark it built in
`writeBundle`, and emit the output once every environment has finished.

Fixes #792

Co-authored-by: Cursor <cursoragent@cursor.com>
@alchemy-version-bot

alchemy-version-bot Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/08575b7

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/08575b7

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/08575b7

…ildApp

Add the world's simplest Vite fixture (a client-only app, no config, no
plugins) and a deploy test for it. Such a project resolves as
`appType: "spa"`, so the Cloudflare Vite plugin declares no
`builder.buildApp` and Vite falls back to the legacy single-environment
builder — the exact code path from #792.

That case also exposed that tracking "all registered environments built"
never completes: the legacy builder only builds the `client` environment,
so the registered `ssr` environment's `writeBundle` never fires. Drop the
per-environment bookkeeping and instead read the collected output lazily;
`viteBuild` already awaits `builder.buildApp()` before reading `output`,
so every environment that actually built has run `writeBundle` by then.

Co-authored-by: Cursor <cursoragent@cursor.com>
@john-royal john-royal changed the title fix(bundle): detect vite build completion in writeBundle, not buildApp fix(bundle): read vite build output after buildApp resolves Jul 9, 2026
@john-royal
john-royal merged commit 87244a5 into main Jul 9, 2026
9 checks passed
@john-royal
john-royal deleted the john/vite-environment-no-build-app branch July 9, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Website.Vite deploy fails on Vite 8: "neither assets nor server output"

1 participant