hapijs / joi

The most powerful data validation library for JS
Other
20.95k stars 1.51k forks source link

order of methods throws exception #2868

Open yovasx2 opened 2 years ago

yovasx2 commented 2 years ago

node 16.16 joi 17.6.1

Joi.object({password: Joi.string().min(6).required().message('Password is required!')}); Uncaught: Error: Cannot apply rules to empty ruleset or the last rule added does not support rule properties at new module.exports (/Users/yovasx2/idpartner/node_modules/@hapi/hoek/lib/error.js:23:19) at module.exports (/Users/yovasx2/idpartner/node_modules/@hapi/hoek/lib/assert.js:21:11) at internals.Base.rule (/Users/yovasx2/idpartner/node_modules/joi/lib/base.js:479:9) at internals.Base.method [as message] (/Users/yovasx2/idpartner/node_modules/joi/lib/extend.js:145:29)

but inverting min and required works

Joi.object({password: Joi.string().required().min(6).message('Password is required!')});

it works