z.email() shows "Invalid input" in production build - E2E suite gives false green because tests never run against the production bundle #2303
First Check
Example CodeManual reproduction (no test runner needed)
1. `docker compose up`
2. Open `http://localhost:5173/login` in a browser
3. Enter invalidemail in the email field, any value in the password field
4. Click **Log In**
5. Observe: **"Invalid input"** is displayed
Expected: **"Invalid email address"**
The same happens on `/signup` with an invalid or empty email field.DescriptionDescriptionWhen running the stack with The E2E tests assert "Invalid email address" and currently pass in CI and via Root causeZod v4 declares The English locale, which maps Because All other failing tests ( CI and
|
Replies: 5 comments
|
Your root cause analysis is spot on. Both issues are real and they compound each other. Issue 1 — Zod v4 tree-shakingZod v4 ships with Your fix is the right call: z.email({ message: "Invalid email address" })Inline messages bypass the locale system entirely and survive tree-shaking. You could also keep a centralized messages object for consistency across the codebase: // src/utils/validationMessages.ts
export const msg = {
email: "Invalid email address",
required: "This field is required",
} as const;
// usage
z.email({ message: msg.email })Issue 2 — Playwright testing the dev server, not the production bundleThis is a really common gap. In webServer: {
command: 'docker compose up nginx --wait',
url: 'http://localhost:80',
reuseExistingServer: !process.env.CI,
},On CI you'd want to ensure the production image is built before Playwright runs. A simpler short-term option is adding a separate Both fixes together eliminate this class of false-green bug entirely — the validation error becomes deterministic regardless of build mode, and the test suite actually exercises what ships to users. |
|
I am happy to open a PR if either of you want to take a look @you-kimono @DaCameraGirl and see if my issue covers yours, I believe this to be something I encountered on |
|
@netopsengineer I do believe they are strictly related. I came up with a very similar solution: commit 61b3c17 I would have opened a PR myself, but the guidelines upon opening one explicitely say to wait for a maintainer to ask you to open it. Even though I do believe this change to be harmless and very much needed, I am inclined to wait for a feedback from the maintainers because it affects the CI pipeline. |
Hi everyone, thanks for the report and for the patience! This was already covered in #2393