Class-validator: fix: error TS2503: Cannot find namespace 'ValidatorJS'.

Created on 21 Nov 2019  路  12Comments  路  Source: typestack/class-validator

Just installed class-validator into a new Nest.js project, also manually intalled types.

Getting the above error for basically all validators when trying to start app:

node_modules/class-validator/validation/Validator.d.ts:383:38 - error TS2503: Cannot find namespace 'ValidatorJS'.

383     isISSN(value: unknown, options?: ValidatorJS.IsISSNOptions): boolean;
donreleased fix

Most helpful comment

@cjancsar try to add this to your tsconfig.json

{
  "compilerOptions": {
    ...
    "typeRoots": ["./node_modules/*/node_modules/@types/"]
  }
...
}

All 12 comments

can you share a repo ? I am not having any problems so I can tr to reproduce and if found , fix the problem

Can close this, not sure what happened, but doing a yarn install somehow fixed it...?

This is now happening on a new project, so bizarre...

I'm using validator itself in my project and I'm running into this issue as well.

Solves the issue in the meantime

Looks like breaking changes in @types/validator. But why you need @types/validator in your project? validator and @types/validator are only internal class-validator dependencies. I think you can completely remove them from your package.json.

I'm using import { normalizeEmail } from 'validator'; in my codebase.

  public findByEmail(unsanitizedEmail: string | string[]) {
    const whereCondition = (email: string) => [
      { email },
      { email: normalizeEmail(email) },
      { unsanitizedEmail: email },
      { unsanitizedEmail: normalizeEmail(email) },
    ];

    return this.findOne({
      where: Array.isArray(unsanitizedEmail)
        ? flatten(unsanitizedEmail.map(whereCondition))
        : whereCondition(unsanitizedEmail),
    });
  }

@vlapo I need validator and @types/validator because I am using sequelize-typescript (https://www.npmjs.com/package/sequelize-typescript) which also has them as a dependency. They should be made peer depedencies of this lib to avoid conflicts like this.

@cjancsar try to add this to your tsconfig.json

{
  "compilerOptions": {
    ...
    "typeRoots": ["./node_modules/*/node_modules/@types/"]
  }
...
}

Please try [email protected]. It should be fixed

@vlapo still facing same issue on [email protected]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renehauck picture renehauck  路  5Comments

golozubov picture golozubov  路  5Comments

twittwer picture twittwer  路  6Comments

binaryangel-noa picture binaryangel-noa  路  3Comments

isergey picture isergey  路  3Comments