Skip to content

Validator.register: TypeError: Cannot set properties of undefined #467

@vedmant

Description

@vedmant

What version of this package are you using?

"validatorjs": "^3.22.1",

What operating system, Node.js, and npm version?

MacOs 12.4
Node v18.13.0
Yarn 1.22.19

I'm using Vite for the build.

What happened?

I have following code:

import * as Validator from 'validatorjs'

Validator.register('amount', value => value.match(/^-?[0-9.,]*$/), 'The :attribute must be a number.');

This gives me error on the Validator.register line above:

Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'amount')
    at Object._setRuleMessage (lang.js:36:34)
    at Validator.register (validator.js:604:8)
    at policy-validation.js:40:11
_

In the source code it errors on line:

this.messages[lang][attribute] = message;

So probably means this.messages[lang] was never set.

What did you expect to happen?

No errors.

Are you willing to submit a pull request to fix this bug?

Maybe if it's simple.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions