Joi library not functioning well

I’m currently in the forms section, in lection 13- Joi to be precised. On initializing the schema object, I get the below error in the console. What could be the cause of this?

1 Like

Are you using the same version of joi mosh’s using? If not, the implementation for validation in joi already changed. You can search for the new implementation in google.

1 Like

Hi, Welcome in here.

Can you specify the exact error message ?
A red wavy underline is not enough to troubleshoot your problem.

As of myself, I did not use the same versions than Mosh and went with the latest version at the time I took the course. Even though he advise to use the same version as himself in the course, React has gone a long enough way to often not be usable anymore.


Yes I am using the exact version, version 13.4

On hovering on the "x’ symbol, I get this message: Uncaught TypeError: Cannot read properties of undefined (reading ‘string’)

My guess is JOI might not be imported properly.

I see no reason for this message to be about username.

Show us how you imported Joi!

  1. do you import joi correctly ?
  2. it shoul be :
    const schema = {



it’s a class property.
So, you don’t have to declare it as a variable.

are you sure ?
how about this example
i put const in schema

to make error showing
try typing then delete all the text

Yes, I am sure about the thing I said.

For class property, you don’t need to use const / let / var to declare it as a property.

class ClassName {
    state = {

    schema = {
        // define schema
    // creating a Joi schema is different in latest version of Joi.
    schema = Joi.object({
        // define schema rules.

am I clear now?

In your example, you are using functional component.
I don’t understand what you want to show in your example!

As @UniqueNospaceShort mentioned, the error is above that line.

yes, you’r right. i’m sorry, for my mistake, because when i learn the course, i converting all the lesson in functional way. I forgot that mosh teaching us with class. and i misunderstand about what have you said “it’s a class property”. I make an example just for showing that its work using a const (functional), sorry @maverick :pray: :pray: :pray:


No problem and no need to apologize.

We make mistakes all the time.

I just wanted to make sure you understand, in class we don’t have to use const / let / var to create a property.

Functional components are the future of React applications!

Keep rocking.

1 Like

Keep rocking, yeah :+1:

I wll recommed everyone to use yup instead of joi

Basic Example with React Hook Form

Schema Validation with React Hook Form

1 Like