8000 Question(v4): What is the behavior of the error message for the `file` schema in `@zod/mini`? · Issue #4262 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Question(v4): What is the behavior of the error message for the file schema in @zod/mini? #4262

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

Closed
chimame opened this issue Apr 23, 2025 · 1 comment

Comments

@chimame
Copy link
Contributor
chimame commented Apr 23, 2025

Overview

Error messages output differ depending on whether the file schema is used in ESM or CJS. Is this the intended behavior?

Details

I checked this with the sample code.

import { file } from '@zod/mini';
const fileEsm = file();
const fileCjs = require('@zod/mini').file();
console.log(fileEsm.safeParse('').error, fileCjs.safeParse('').error);
// $ZodError {
//   issues: [
//     {
//       expected: 'file',
//       code: 'invalid_type',
//       path: [],
//       message: 'Invalid input: expected file, received string'
//     }
//   ]
// } $ZodError {
//   issues: [
//     {
//       expected: 'file',
//       code: 'invalid_type',
//       path: [],
//       message: 'Invalid input' <-- different error messages are output.
//     }
//   ]
// }
```ts
@colinhacks
Copy link
Owner

Zod Mini isn't supposed to load the English locale by default...without a locale all error messages default to "Invalid input". Perhaps the code that loads the en.ts locale in "zod/v4" is getting eagerly executed in one environment but not the other?

That said, I'm not able to replicate on the latest betas. How are you running this file? Could you upgrade and again with the latest beta?


PS: Note that you'll need to rewrite your v4 imports to "zod/v4-mini" after upgrading; for more information, see #4371 for details

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

No branches or pull requests

2 participants
0