Lesha-spr / react-validation

React Validation Components
336 stars 116 forks source link

Module not found: Can't resolve 'validator' with version 3.0.7 #169

Open aminacelik opened 6 years ago

aminacelik commented 6 years ago

I get this error with react-validation@3.0.7:

./src/utils/Validators.js
Module not found: Can't resolve 'validator' in '/Users/xxx/xxx/xxx/xxx/src/utils'

This is my ./src/utils/Validators.js file:


import React from 'react';
import validator from 'validator';
import ValidationErrorMsg from '../containers/ValidationErrorMsg';

export const required = (value) => {
  if (!value.toString().trim().length) {
    return (
        <ValidationErrorMsg msg={'Required field.'} />
    );
  }
};

export const email = (value) => {
  if (!validator.isEmail(value)) {
    return "{ value } is not a valid email."
  }
};

export const password = (value, props, components) => {
    if (value !== components['confirm'][0].value) {
        return <span className="error">Passwords are not equal.</span>
    }
};

export const exactLength = (value, props) => {
  if (value.toString().trim().length !== props.exactLength) {
    return <span className="error">The value should be {props.exactLength} characters long.</span>
  }
}
```;
cblaettl commented 6 years ago

validator is a separate npm package. If you want to use it, you have to install it: npm install validator.

yhalapup commented 4 years ago

@aminacelik @cblaettl The solution is simple: in package.json move validator library from devDependencies to dependencies.