react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.67k stars 151 forks source link

`Joi` resolver crashes on `File` validation #668

Closed romanstetsyk closed 1 week ago

romanstetsyk commented 3 months ago

Describe the bug The validator crashed while trying to validate a File upload with an error Cannot read properties of undefined (reading 'length') . The schema like this works fine:

const file = Joi.object<File>().label("File");

But as soon as I try to add the fields to validate it crashes.

const file = Joi.object<File>({
  name: Joi.string().max(255).required(),
}).label("File");

To Reproduce Steps to reproduce the behavior:

  1. Go to the codesandbox below
  2. Drag any file to the upload area
  3. Click 'submit'
  4. See error

Codesandbox link (Required)

https://codesandbox.io/p/sandbox/joi-error-hcktkx?file=%2Fsrc%2FApp.tsx%3A19%2C42

Expected behavior Such an error should not appear.

Screenshots

image

Desktop (please complete the following information):

jorisre commented 1 week ago

This isn't a resolver issue, but a Joi issue. As I'm not familiar with Joi, I can't help you with using Joi validation for File uploads. The error you're seeing is a TypeError: Illegal invocation.

Screenshot 2024-07-03 at 10 34 28