typestack / class-validator

Decorator-based property validation for classes.
MIT License
10.89k stars 786 forks source link

fix: Cannot find namespace 'ValidatorJS' in 0.14.x #2370

Closed mhp-borisbojic closed 8 months ago

mhp-borisbojic commented 8 months ago

Description

With version 0.14.x of class-validator, our tsc (5.3.3) build command suddenly fails.

Minimal code-snippet showcasing the problem

tsc -p tsconfig.build.json  

../../node_modules/class-validator/types/decorator/string/IsAlpha.d.ts:8:58 - error TS2833: Cannot find namespace 'ValidatorJS'. Did you mean 'validator'?

8 export declare function isAlpha(value: unknown, locale?: ValidatorJS.AlphaLocale): boolean;
                                                           ~~~~~~~~~~~

../../node_modules/class-validator/types/decorator/string/IsAlpha.d.ts:13:42 - error TS2833: Cannot find namespace 'ValidatorJS'. Did you mean 'validator'?

13 export declare function IsAlpha(locale?: ValidatorJS.AlphaLocale, validationOptions?: ValidationOptions): PropertyDecorator;
                                            ~~~~~~~~~~~

../../node_modules/class-validator/types/decorator/string/IsAlphanumeric.d.ts:8:65 - error TS2833: Cannot find namespace 'ValidatorJS'. Did you mean 'validator'?

8 export declare function isAlphanumeric(value: unknown, locale?: ValidatorJS.AlphanumericLocale): boolean;
                                                                  ~~~~~~~~~~~

../../node_modules/class-validator/types/decorator/string/IsAlphanumeric.d.ts:13:49 - error TS2833: Cannot find namespace 'ValidatorJS'. Did you mean 'validator'?

13 export declare function IsAlphanumeric(locale?: ValidatorJS.AlphanumericLocale, validationOptions?: ValidationOptions): PropertyDecorator;
                                                   ~~~~~~~~~~~

../../node_modules/class-validator/types/decorator/string/IsCurrency.d.ts:8:62 - error TS2833: Cannot find namespace 'ValidatorJS'. Did you mean 'validator'?

8 export declare function isCurrency(value: unknown, options?: ValidatorJS.IsCurrencyOptions): boolean;

tsconfigs:

  "extends": "./tsconfig.json",
  "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "esModuleInterop": true
  },
  "exclude": ["node_modules", "dist"]
}

package.json

"dependencies": {
    "@aws-sdk/client-s3": "^3.473.0",
    "@aws/dynamodb-data-mapper": "^0.7.3",
    "@aws/dynamodb-data-mapper-annotations": "^0.7.3",
    "@aws/dynamodb-expressions": "^0.7.3",
    "@nestjs/common": "^10.2.10",
    "@nestjs/core": "^10.2.10",
    "@nestjs/platform-express": "^10.2.10",
    "@nestjs/swagger": "^7.1.17",
    "aws-lambda": "^1.0.7",
    "aws-sdk": "^2.1518.0",
    "aws-serverless-express": "^3.4.0",
    "axios": "^1.6.2",
    "axios-retry": "^4.0.0",
    "class-transformer": "^0.5.1",
    "class-validator": "0.13.2",
    "cls-hooked": "^4.2.2",
    "dotenv": "^16.3.1",
    "express": "^4.18.2",
    "express-validator": "^7.0.1",
    "https-proxy-agent": "^7.0.2",
    "json5": "^2.2.3",
    "jsonwebtoken": "^9.0.2",
    "jwks-rsa": "^3.1.0",
    "moment": "^2.29.4",
    "node-cache": "^5.1.2",
    "node-request-context": "^1.0.5",
    "request-context": "^2.0.0",
    "rimraf": "^5.0.5",
    "rxjs": "^7.8.1",
    "sinon": "^17.0.1",
    "swagger-ui-express": "^5.0.0",
    "uuid": "^9.0.1",
    "winston": "^3.11.0",
    "xkpasswd": "^1.0.5"
  },
  "devDependencies": {
    "@nestjs/testing": "^10.2.10",
    "@types/express": "^4.17.21",
    "@types/got": "^9.6.12",
    "@types/jest": "^29.5.11",
    "@types/node": "^20.10.4",
    "@types/supertest": "^2.0.16",
    "@types/uuid": "^9.0.7",
    "@typescript-eslint/eslint-plugin": "6.18.1",
    "@typescript-eslint/parser": "6.18.1",
    "eslint": "8.56.0",
    "eslint-config-prettier": "9.1.0",
    "eslint-plugin-prettier": "5.1.3",
    "husky": "^8.0.3",
    "jest": "^29.7.0",
    "lint-staged": "^15.2.0",
    "prettier": "^3.1.1",
    "supertest": "^6.3.3",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.2",
    "tsc-watch": "^6.0.4",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.3.3"
  },

Expected behavior

Tsc build command works as before.

Actual behavior

It worked for 2 months without issues, but now results in the output above. If we set back the version to 0.13.x, it works without any issues or error messages.

jonparkdev commented 8 months ago

https://github.com/typestack/class-validator/commit/0042559f45dcfd81d24bb0a46128ba3f32728fd5

Looks like its from the latest commit

sph3rex commented 8 months ago

I think it was fixed in tag 0.14.1 but I guess you forgot to bump also the package.json version since it still says 0.14.0. Probably because of that there's no npm release?! https://github.com/typestack/class-validator/commit/0042559f45dcfd81d24bb0a46128ba3f32728fd5 in fact fixes the imports, because @types decided that it's a good moment to update all the validator versions since 13.0.0 in the release 2 days ago.

PS: was wondering why you don't release separate tarballs with cjs/, esm2015/ since right now people are stucked waiting for npm release rather than using the git typestack/class-validator#0.14.1 tag.

braaar commented 8 months ago

My bad, folks, this should be fixed in a few minutes.

braaar commented 8 months ago

I need an approval on #2373 in order to merge it (develop is protected, so I can't push directly myself and my PR needs an approval)

fabrice-toussaint commented 8 months ago

How long does it take for NPM to pick this up?

braaar commented 8 months ago

This was my mistake. The release has now succeeded. See comments in #2371 and #2373

Sorry about the mess.

sph3rex commented 8 months ago

This has been fixed in the new published version: 0.14.1. Thank you @braaar !

github-actions[bot] commented 7 months ago

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.