简体   繁体   English

是的验证库类型错误:是的__WEBPACK_IMPORTED_MODULE_0__ 不是函数

[英]yup validation library TypeError: yup__WEBPACK_IMPORTED_MODULE_0__ is not a function

I have installed yup and tried to validate my form with this, however when I try to import it to a file I get this error.我已经安装了 yup 并尝试使用此验证我的表单,但是当我尝试将其导入文件时,我收到此错误。 I do not even run the handler, it just errors me out on page load.我什至不运行处理程序,它只是在页面加载时出错。 I use it with react.我将它与反应一起使用。

this is my code这是我的代码

import * as yup from "yup";

export const detailsSchema = yup.object().shape({
    cheeseType: yup()
        .string()
        .isRequired()
});

I tried to rm -rf node_modules, I did not help.我试图 rm -rf node_modules,我没有帮助。

Thanks for helping me out.谢谢你的协助。

It solved this error I used wrong method - isRequired() instead of required() and also here I was wrong:它解决了这个错误我使用了错误的方法 - isRequired() 而不是 required() 并且在这里我错了:

cheeseType: yup()
        .string()
        .isRequired()

should be应该

cheeseType: yup
        .string()
        .isRequired()

so the correct schema looks like所以正确的架构看起来像

cheeseType: yup
        .string()
        .required()

All the best!祝一切顺利! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM