Closed foxx closed 10 years ago
I've updated parsley to fix this behavior, could you have a try with latest master version?
Thanks
The issue is still present in 2.0.4
Validator = 'undefined' !== typeof Validator ? Validator : module.exports;
shouldn't you also check for module (strict settings) ?
Validator = 'undefined' !== typeof Validator ? Validator : ('undefined' !== typeof module ? module.exports : null);
I am getting this error too when using 2.0.4 with RequireJS. 2.0.3 was fine.
ReferenceError: module is not defined
--> Validator = 'undefined' !== typeof Validator ? Validator : module.exports;
http://.../components/parsleyjs/dist/parsley.js, Line 866
Suggestion by @iongion also doesn't work:
TypeError: Validator is null
--> return $.extend(new Validator.Assert().Required(), { priority: 512 });
http://.../components/parsleyjs/dist/parsley.js, Line 949
I'm also running into this, or very similar issue with AMD loader... I'm getting this error when running 2.0.4.
Uncaught ReferenceError: module is not defined
thrown from parsley.js 866
Validator = 'undefined' !== typeof Validator ? Validator : module.exports;
Also tried @iongion suggestion and then I get the same error as @perfusorius.
Uncaught TypeError: Cannot read property 'Assert' of null parsley.js:949
ParsleyValidator.validators.required parsley.js:949
getPriority parsley.js:1495
ConstraintFactory parsley.js:1497
ParsleyField.addConstraint parsley.js:1602
ParsleyField._bindConstraints parsley.js:1637
ParsleyField parsley.js:1529
Parsley.bind parsley.js:1982
Parsley.init parsley.js:1899
Parsley parsley.js:1876
$.fn.parsley.$.fn.psly
Was having the same problem on a new RequireJS project. I've applied a fix for this on a fork here: https://github.com/jimdoyle82/Parsley.js.git Wasn't sure how to run the tests though so haven't done a pull request yet and won't have time for a few days. Feel free to clone the fork though in the meantime. Problem was that the Validator object (in Validator.js) wasn't defined on the global namespace once RequireJS dependency as removed in the Grunt build. So I modified the Grunt build to add a global variable called "Validator" and made the self-executing wrapper function return an object with Validator and Assert properties. Everything seems to be working well now.
Hi @jimdoyle82, your code looks great ! Could you make a PR, I'll test it and finish it if you don't have time.
Best
Ok, that's done. Over to you.
This issue should have been fixed with 2.0.5.
Feel free to reopen if not the case.
Best
Thanks @guillaumepotier @jimdoyle82
I can confirm release 2.0.5 works in my require.js setup, and resolves the issue I had reported. Great work, thanks again!
There is a problem with the AMD approach used
Notice how
ParsleyValidator
uses global refValidator
, however in the definition aboveValidator
is only written tothis
if exports isundefined
. For AMD, this will never be so, and as such theValidator
module goes intoexports
.This resolves in the following failure;
The most immediate fix seems to use something like;
However this has not been fully tested and would advice one of the core devs look at this.