Skip to content

vite: do not reuse a failed build - #95

Open
cgaaf wants to merge 1 commit into
solidjs:mainfrom
cgaaf:fix/vite-stale-failed-build
Open

cgaaf wants to merge 1 commit into
solidjs:mainfrom
cgaaf:fix/vite-stale-failed-build

Conversation

@cgaaf

@cgaaf cgaaf commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #84.

The Vite front end kept serving a failed build after the imported module that caused it was restored or fixed. #84 has the reproduction; it still reproduces on main at e650b85.

Change

One condition in build() (compiler/vite.mjs): a cached build is reused only if it compiled.

-    if (prior && fresh(prior)) return prior;
+    // a failed build's stamps miss what it failed to find (MO-6 names the importer), so it is never reused
+    if (prior?.out.modules && fresh(prior)) return prior;

A failed build stamps its entry and the files its diagnostics name. MODULE_NOT_FOUND and NOT_EXPORTED (MO-6) name the importer, not the module that is missing or lacks the export, so fixing that module changes no stamp. A failed build can't tell when it has gone stale, so it is built again on the next request.

A program that compiles is cached as before: five compiles of an unchanged examples/shop (the entry, its three dependencies, the entry again) make one native build.

Test

compiler/test/node.mjs gets one case, so it runs in the compiler workflow on each platform. Through the front end it removes a dependency, sees MODULE_NOT_FOUND at the importer, renames the file back (its mtime unchanged), and compiles the entry and the dependency again. It then does the same with a front end whose first compile was the failing one and whose next request is the dependency (containing()'s cold path). With main's vite.mjs the case fails on the stale MODULE_NOT_FOUND.

I put it there and not in test/vite.mjs because no workflow runs that file, and the case needs only rx().compile(). Say if you'd rather have it in test/vite.mjs.

Verified

On macOS arm64, Node 26.13.1, rustc 1.98.1 (CI pins 1.99.1), Solid at the pinned 30e7805eb:

  • ref: npm test exits 0 with no failing check; npm run oracle and npm run compiled 135 pass; npm run ssr 128 pass, 7 skip; npm run types 181 pass. No scenario's result changed.
  • compiler: npm test 7 pass; cargo test passes; test/vite.mjs 16 pass against solid-vite-plugin 3.0.1 (cbc6ce2).
  • runtime: npm test passes.
  • The cases from Vite front end keeps serving a failed build after the missing/broken imported module is fixed #84, rerun on this branch, all recover on the next compile: the module missing and restored, the first compile made while it is missing, NOT_EXPORTED fixed with the mtime kept, the first compile made while the module is unreadable (chmod 000), and a dependency requested after its program failed. On main all five keep the error.

The compiler workflow, run on my fork at this commit, is green on all six builds, and the new case passes on Linux x64 and arm64, macOS arm64, Windows x64 and WASI: https://github.com/cgaaf/reactivescript/actions/runs/45316052946

Cost

While a program does not compile, each request for it builds it again. On examples/shop (4 modules), per request:

Request main (cached failure) This branch
Entry, catalog.rx missing 0.03 ms 0.36 ms
Dependency, catalog.rx missing 0.56 ms 0.84 ms
Entry, NOT_EXPORTED from the checker – 0.40 ms
Dependency, NOT_EXPORTED from the checker – 1.03 ms

A dependency request costs more because containing() walks the project for a program that holds it, as it does on main. main has no figure for NOT_EXPORTED because it was still serving the earlier failure.

Alternatives

  • Don't store a failed build at all, so the last build that compiled stays in builds. A dependency request would then go straight to its program and skip the walk. But I tried it: with two programs sharing a module, one of them broken and the shared module then edited, containing() picks the broken program's old build and reports its diagnostics for a module the other program still compiles. With this branch the same request compiles. Fixing that means having containing() try each candidate, which is more than Vite front end keeps serving a failed build after the missing/broken imported module is fixed #84 needs.
  • Have the crate return the paths it read or failed to read, and stamp those. This would let failed builds be cached safely. It is a change to the native output, so I left it out.

Not addressed

A build that compiled is still judged by the mtimes of its emitted modules alone. A module made unreadable (chmod 000) after a good build keeps being served, since chmod doesn't change the mtime. That is separate from #84 and unchanged here.

No version is bumped and CHANGELOG.md is untouched.


Found while building a component library on ReactiveScript. Diagnosed, written and tested with Claude Fable 5.2 (in Claude Code), which ran everything listed under Verified on the final commit. Codex (gpt-6.2-astra) and Gemini (gemini-4-carbon-high) reviewed the change; moving the test into test/node.mjs and the first alternative came from that review.

🤖 Generated with Claude Code

A failed build stamps its entry and the files its diagnostics name. MO-6 names the importer, not the module that is
missing or lacks the export, so restoring that module changed no stamp and the failed build was served until the
entry or the importer was touched, or the dev server restarted (solidjs#84). Only a build that compiled is reused now; a
program that does not compile is built again on each request.

compiler/test/node.mjs: removes a dependency, sees MODULE_NOT_FOUND through the front end, puts the file back with
its mtime unchanged, and compiles the entry and the dependency again, warm and cold.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Vite front end keeps serving a failed build after the missing/broken imported module is fixed

1 participant