Whenever I try to initialize yup schema in next.js its shows the following error.
import * as Yup from "yup";
const experienceSchema = Yup.object.shape({
experience: Yup.string().required(),
})
The error I'm getting
Server Error
ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
This error happened while generating the page. Any console logs will be displayed in the terminal window.
This is similar to every page wherever I try to import yup. I tried with different versions also but still, the error persists.
Yup Version : 0.32.10
Next Version : 12.0.8
CodePudding user response:
Brackets missing in the object. I got the error. It should be this.
const experienceSchema = Yup.object().shape({
experience: Yup.string().required(),
})
instead of this
const experienceSchema = Yup.object.shape({
experience: Yup.string().required(),
})
CodePudding user response:
yup.object().shape vs yup.object.shape is the issue. I made a stackblitz that shows all and your code working, it simply consoles out value
https://stackblitz.com/edit/nextjs-7etrjq?file=pages/index.js
