【问题标题】:yup validation library TypeError: yup__WEBPACK_IMPORTED_MODULE_0__ is not a function是的验证库 TypeError:yup__WEBPACK_IMPORTED_MODULE_0__ 不是函数
【发布时间】:2021-12-21 22:24:30
【问题描述】:

我已经安装了 yup 并尝试使用它来验证我的表单,但是当我尝试将其导入文件时出现此错误。我什至不运行处理程序,它只是在页面加载时出错。我用它来反应。

这是我的代码

import * as yup from "yup";

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

我尝试 rm -rf node_modules,但没有帮助。

感谢您帮助我。

【问题讨论】:

  • 您可以将导入更改为:import * as Yup from "yup"; 并重试吗?

标签: javascript reactjs validation yup


【解决方案1】:

它解决了这个错误我使用了错误的方法 - isRequired() 而不是 required() 并且这里我错了:

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

应该是

cheeseType: yup
        .string()
        .isRequired()

所以正确的架构看起来像

cheeseType: yup
        .string()
        .required()

一切顺利! :)

【讨论】:

    猜你喜欢
    • 2016-11-07
    • 2018-02-21
    • 1970-01-01
    • 2018-02-25
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2016-06-12
    相关资源
    最近更新 更多