TypeError: Expected string but received a undefined

expected cwd to be of type string but received type undefined
npm validator
react-validator
express-validator
module not found can t resolve validator
validate js
npm email validation
validation in node js

While validating the name and password before posting it to the mongodb database it is showing some errror

const Validator = require('validator');
const isEmpty = require('./is-empty');

module.exports = function validateRegisterInput(data){
    let errors = {};

    data.name = !isEmpty(data.name) ? data.name : '';
    data.email = !isEmpty(data.email) ? data.email : '';
    data.password = !isEmpty(data.password) ? data.password : '';
    data.password = !isEmpty(data.password2) ? data.password2 : '';


    if((!Validator.isLength(data.name , { min:2, max:20 }))){
        errors.name = 'Name must be between 2 and 20 characters';
    }

    if(Validator.isEmpty(data.name)){
        errors.name ='Name field is required';
    }

    if(Validator.isEmpty(data.email)){
        errors.email ='Email field is required';
    }

    if(Validator.isEmail(data.email)){
        errors.email ='Email is invalid';
    }

    if(Validator.isEmpty(data.password)){
        errors.password ='Password field is required';
    }

    if(Validator.isLength(data.password, {min:8 })){
        errors.password ='Password field is required';
    }

    if(Validator.isEmpty(data.password2)){
        errors.password2 ='Confirm Passwords field is required';
    }

    if(Validator.equals(data.password, data.password2)){
        errors.password2 = 'Passwords must match';
    }

    return {
        errors,
        isValid: isEmpty(errors)
    };
};

error showing in postman

TypeError: Expected string but received a undefined.    at assertString (E:\MERN\devconnector\node_modules\validator\lib\util\assertString.js:28:11)    at Object.isEmpty (E:\MERN\devconnector\node_modules\validator\lib\isEmpty.js:19:29)    at validateRegisterInput (E:\MERN\devconnector\validation\register.js:38:18)    at router.post (E:\MERN\devconnector\routes\api\users.js:27:33)    at Layer.handle [as handle_request] (E:\MERN\devconnector\node_modules\express\lib\router\layer.js:95:5)    at next (E:\MERN\devconnector\node_modules\express\lib\router\route.js:137:13)    at Route.dispatch (E:\MERN\devconnector\node_modules\express\lib\router\route.js:112:3)    at Layer.handle [as handle_request] (E:\MERN\devconnector\node_modules\express\lib\router\layer.js:95:5)    at E:\MERN\devconnector\node_modules\express\lib\router\index.js:281:22    at Function.process_params (E:\MERN\devconnector\node_modules\express\lib\router\index.js:335:12)    at next (E:\MERN\devconnector\node_modules\express\lib\router\index.js:275:10)    at Function.handle (E:\MERN\devconnector\node_modules\express\lib\router\index.js:174:3)    at router (E:\MERN\devconnector\node_modules\express\lib\router\index.js:47:12)    at Layer.handle [as handle_request] (E:\MERN\devconnector\node_modules\express\lib\router\layer.js:95:5)    at trim_prefix (E:\MERN\devconnector\node_modules\express\lib\router\index.js:317:13)    at E:\MERN\devconnector\node_modules\express\lib\router\index.js:284:7

Please check where you declared isEmpty function in your isEmpty.js file, you probably used an arrow function, which shouldn't be.

const isEmpty = value => {
    value === undefined ||
    value === null ||
    (typeof value === "Object" && Object.keys(value).length === 0) ||
    (typeof value === "string" && value.trim().length === 0)

}

So, remove the curly brackets at the end of the arrow function "{}", it shouldn't be there.

undefined error when using a validator on Redux state variable , TypeError: Expected string but received a undefined. assertString node_modules​/validator/lib/util/assertString.js:40 37 | } 38 | } 39 | > 40 | throw new  Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

try adding this :

data.password**2** = !isEmpty(data.password2) ? data.password2 : ''; 

TypeError: expected string but received array postman, TypeError: expected string but received array postman - node.js. MISSING_FIELD parameter in my code I get undefined. All fields except date in the model is  While working with functions, there may be an error called “TypeError expected string or bytes-like object”. This is usually encountered when a function that you are using or have defined is fed an integer or float. It might be expecting a string or byte like object but as it has received something else, it raises an error.

You must add

if("HERE"Validator.equals(data.password, data.password2)){
        errors.password2 = 'Passwords must match';
}

and change "data.password" to data.password2 in line 10

Expected `cwd` to be of type `string` but received type `undefined , stylelint src/**/*.css TypeError: Expected `cwd` to Expected `cwd` to be of type `string` but received type `undefined` #3885. Closed. 🐛 Bug Report I have a number of repos in our enterprise setup that are running into the following error: Test suite failed to run TypeError: Path must be a string. Received undefined at buffer.re

I recommend to write data in JSON format and then check the content-type which should be application/json. the same issue happened to me and I resolve it the way I mentioned.

TypeError: Expected `cwd` to be of type `string` but received type , TypeError: Expected `cwd` to be of type `string` but received type `undefined` #​265. Closed. bartdelange opened this issue on Jan 12, 2019 · 11 comments. TypeError: string indices must be integers, not str donc je pense ça vient "(json.dumps(_level) ['play_log_id'] " mais du je ne sais pas comment corriger l'erreur. Edité par Tevqo 26 juin 2020 à 21:44:56

If you are writing arrow function with multiple lines then We should have explicit return value or result.

  const isEmpty = value => {
  return (value === undefined ||
    value === null ||
    (typeof value === "Object" && Object.keys(value).length === 0) ||
    (typeof value === "string" && value.trim().length === 0))

};

module.exports = isEmpty;

Note: Please refer ES6 documentation for clarity : http://es6-features.org/

Meme Overflow on Twitter: "TypeError: Expected string but received , Copy link to Tweet; Embed Tweet. TypeError: Expected string but received a undefined https://stackoverflow.com/questions/58204450/58216 … Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together

Node.js Error Handling - TypeError, A deep dive into the TypeError in Node.js, with sample code showing (e instanceof TypeError) { // Output expected TypeErrors. logging.log(e); } 'string') { throw new TypeError(`'Author' value of (${value}) must be a string, not ${typeof value}. Received 12345 at assertPath (path.js:28:11) at Object.parse  TypeError: Path must be a string. Received undefined - when require a module. TypeError: Path must be a string. Received undefined at assertPath (path.js:7:11)

Node.js v14.4.0 Documentation, ifError(value); assert.match(string, regexp[, message]); assert. message: '​Expected the func function to be executed 2 time(s) but was // executed 0 time(s). If the message parameter is undefined, a default error message is assigned. The API for accessing this information is currently not considered public, but using the  [Enter steps to reproduce:] open a really big project with .gitignored 'build' directory make project from other console, so contents of this build directory start to change very quickly (downloading and unpacking linux kernel, for examp

7 Tips to Handle undefined in JavaScript, TypeError: 'undefined' is not a function; TypeError: Cannot read property In this sense, typeof operator returns 'undefined' string for an Tip 1: Favor const , otherwise use let , but say goodbye to var The function returns the initial array [​10] without modifications, instead of the expected [0, 10, false] . Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

Comments
  • Take a look again at How to Answer. This is better suited to a comment, since it's more a general suggestion than a complete answer to a specific problem