How to fix Yup cannot read property object of undefined
If you’re using TypeScript with Yup, you might be running into this error:
TypeError: Cannot read property 'object' of undefined
And this is what your code may look like
import yup from 'yup';
const schema = yup.object().shape({});
To fix the error message above, make sure you have types for Yup installed.
npm i -D @types/yup
The next thing to update is how you import Yup into your TypeScript file
import * as yup from 'yup';
That’s it!
I like to tweet about JavaScript and post helpful code snippets. Follow me there if you would like some too!