Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未处理的PromisejectionWarning错误,使用Yup_Javascript_Reactjs_React Native_React Router_Yup - Fatal编程技术网

Javascript 未处理的PromisejectionWarning错误,使用Yup

Javascript 未处理的PromisejectionWarning错误,使用Yup,javascript,reactjs,react-native,react-router,yup,Javascript,Reactjs,React Native,React Router,Yup,我收到未处理的PromisejectionWarning:TypeError:Yup.string.required不是位于_callee$error from Yup的函数 每当我使用邮递员发送邮件请求时 import * as Yup from "yup"; import {PROVIDER_ENUM} from './customer.model'; export const create = async (req, res) => { const {token, provi

我收到未处理的PromisejectionWarning:TypeError:Yup.string.required不是位于_callee$error from Yup的函数 每当我使用邮递员发送邮件请求时

import * as Yup from "yup";
import {PROVIDER_ENUM} from './customer.model';
export const create = async (req, res) => {
    const {token, provider } = req.body;

    const bodySchema = Yup.object().shape({
        token: Yup.string().required(),
        provider: Yup.string()
          .oneOf(PROVIDER_ENUM)
          .required(),
      });
    try {
        await bodySchema.validate({token, provider});
        res.status(201).json({message:'success'})
    } catch (error) {
        res.status(400).json({ message: error.message});
    }
}
以下是完整的错误消息:

(node:11240) UnhandledPromiseRejectionWarning: TypeError: Yup.string.required is not a function
    at _callee$ (C:/native/lasprice/server/src/modules/customer/customer.controller.js:10:27)
    at tryCatch (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:65:40)
    at Generator.invoke [as _invoke] (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:303:22)
    at Generator.prototype.(anonymous function) [as next] (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:117:21)
    at step (C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:191)
    at C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:437
    at new Promise (<anonymous>)
    at C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:99
    at create (C:/native/lasprice/server/src/modules/customer/customer.controller.js:6:14)
    at Layer.handle [as handle_request] (C:\native\lasprice\server\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\native\lasprice\server\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\native\lasprice\server\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\native\lasprice\server\node_modules\express\lib\router\layer.js:95:5)
    at C:\native\lasprice\server\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\native\lasprice\server\node_modules\express\lib\router\index.js:335:12)
    at next (C:\native\lasprice\server\node_modules\express\lib\router\index.js:275:10)
(node:11240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(节点:11240)未处理的PromisejectionWarning:TypeError:Yup.string.required不是函数
在_callee$(C:/native/lasprice/server/src/modules/customer/customer.controller.js:10:27)
在tryCatch(C:\native\lasprice\server\node\u modules\registrator runtime\runtime.js:65:40)
在Generator.invoke[as _invoke](C:\native\lasprice\server\node\u modules\registrator runtime\runtime.js:303:22)
在Generator.prototype.(匿名函数)[下一步](C:\native\lasprice\server\node\u modules\registrator runtime\runtime.js:117:21)
在步骤(C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:191)
在C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:437
在新的承诺()
位于C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:99
创建时(C:/native/lasprice/server/src/modules/customer/customer.controller.js:6:14)
在Layer.handle[作为handle\u请求](C:\native\lasprice\server\node\u modules\express\lib\router\Layer.js:95:5)
下一步(C:\native\lasprice\server\node\u modules\express\lib\router\route.js:137:13)
在Route.dispatch(C:\native\lasprice\server\node\u modules\express\lib\router\Route.js:112:3)
在Layer.handle[作为handle\u请求](C:\native\lasprice\server\node\u modules\express\lib\router\Layer.js:95:5)
在C:\native\lasprice\server\node\u modules\express\lib\router\index.js:281:22
在Function.process_参数处(C:\native\lasprice\server\node\u modules\express\lib\router\index.js:335:12)
下一步(C:\native\lasprice\server\node\u modules\express\lib\router\index.js:275:10)
(节点:11240)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:1)
(节点:11240)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。

是否
Yup.string()
返回具有
required
方法的内容?如果不是,那就是问题所在-问题是,错误消息表明
Yup.string.required
不是一个函数。。。您在发布的代码中从来没有这样做过,而是
Yup.string().required()
-因此,您发布的代码可能并不代表您遇到问题的代码,我应该创建一个函数吗?不。。。但是错误消息与您显示的代码无关-您显示的代码与
Yup.string().required()
-但是错误可能在您可能正在执行的某个地方
Yup.string.required()
-您看到区别了吗?在第10行显示
customer.controller.js
返回具有
必需的
方法的内容?如果不是,那就是问题所在-问题是,错误消息表明
Yup.string.required
不是一个函数。。。您在发布的代码中从来没有这样做过,而是
Yup.string().required()
-因此,您发布的代码可能并不代表您遇到问题的代码,我应该创建一个函数吗?不。。。但是错误消息与您显示的代码无关-您显示的代码与
Yup.string().required()
-但是错误可能在您可能正在执行的某个地方
Yup.string.required()
-您看到了区别,对吗?在第10行显示
customer.controller.js