fix(test): stop Vite's SSR transform from dropping zod's z export - #491
Open
yange-siegenia wants to merge 1 commit into
Open
fix(test): stop Vite's SSR transform from dropping zod's z export#491yange-siegenia wants to merge 1 commit into
z export#491yange-siegenia wants to merge 1 commit into
Conversation
The suite could not run at all. zod's entry does `import * as z from
'./v4/classic/external.js'`, then both `export *` from that same module
and `export { z }`. Vite's SSR transform loses the `z` binding in that
combination, so `import { z } from 'zod'` arrives as undefined and every
module that declares a schema throws on load -- which is nearly all of
them.
Pre-bundling zod with esbuild sidesteps the SSR transform and re-exports
it correctly. The two other plausible fixes were tried and do not work:
externalizing zod so Node loads it natively still fails, and so does
removing the SSR optimizer entirely, so this is specific to the transform
rather than to the optimizer being on.
Verified against a pgvector Postgres: 13946 passing. The five remaining
failures pass in isolation and are parallelism flakes that predate this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a clean checkout with the committed lockfile,
bun run testfails to run essentially the whole suite. Every module that declares a zod schema throws on load, which is most of the server.Cause
zod 4.4.3's entry point is:
Vite's SSR transform loses the
zbinding in that specific combination — a namespace import that is re-exported by name alongside anexport *of the same module.import { z } from 'zod'therefore arrives asundefined, whileimport * as z from 'zod'still works.Minimal reproduction:
Fix
Add
zodto the SSR optimizer'sincludelist so esbuild pre-bundles it, which sidesteps the SSR transform and re-exports it correctly.Two other plausible fixes were tried and do not work, which is why the comment records them:
So this is specific to the SSR transform rather than to the optimizer being enabled.
Verification
Confirmed against
main(currently ce3d245): the reproduction above fails without this change and passes with it.Full suite against a real
pgvector/pgvector:pg17Postgres with migrations applied: 13,946 passing. The handful of remaining failures all pass when their files are run in isolation — they are pre-existing parallelism flakes under full-suite CPU contention, in auth components and email routing, unrelated to this change.I hit this while working on something unrelated in a fork, and it looked worth sending upstream on its own.