question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsley is undefined when loading from minified file?

See original GitHub issue

I’m pretty new to AMD / require.js as well as to Parsley, so excuse me if this turns out to be a user error…

I’m loading Parsley through AMD using require.js, but for some reason I’m getting undefined as the Parsley object.

Here is the strange thing: If I load the source file of Parsley (I have to add some paths so it can find it’s own sub modules) it does work!

I created a JS Fiddle that demonstrates my issue, but for some reason I could only get this to work using require. In my actual code I’m using define

Here is my code using the minified script:

require.config({
    paths: {
        'jquery': '//code.jquery.com/jquery-2.1.4.min',
        'parsley': '//cdn.rawgit.com/download/Parsley.js/2.1.2/dist/parsley.min',
    }
});
define(['parsley'], function(Parsley){
    alert('Parsley is ' + Parsley);   // ---> alerts: 'Parsley is undefined'
});

If I use the source version of Parsley, it does work:

require.config({
    paths: {
        'jquery': '//code.jquery.com/jquery-2.1.4.min',
        'parsley': '//cdn.rawgit.com/download/Parsley.js/2.1.2/src/parsley',
        'i18n': '//cdn.rawgit.com/download/Parsley.js/2.1.2/src/i18n',
        'validator': '//cdn.rawgit.com/guillaumepotier/validator.js/1.1.2/dist/validator.min'
    }
});

define(['jquery', 'parsley'], function($, Parsley){
    alert('Parsley is ' + Parsley);   // --->  alerts 'Parsley is [Object object]'
});

If I leave out the dependency on jQuery, like so:

define(['parsley'], function(Parsley){
    alert('Parsley is ' + Parsley);
});

I get two errors:

  • Uncaught ReferenceError: jQuery is not defined (anonymous function) @ en.js:6
  • Uncaught ReferenceError: $ is not defined (anonymous function) @ pubsub.js:7

I think this is a bug. en.js and pubsub.js should define themselves and declare the dependency on jQuery…

If I add the explicit dependency on jQuery to the define using the minified Parsley, it doesn’t actually help. Neither does adding the paths for i18n and validator. Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Downloadcommented, Jun 23, 2015

I tried it out and adding return window.Parsley; to src/wrap/append.js fixes this issue in my testing. So I just went ahead and made a PR of it.

0reactions
guillaumepotiercommented, Jun 23, 2015

Indeed. Thank you. Best

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsley.js console errors - jquery - Stack Overflow
I thought I followed the doc exactly, but I keep getting errors. Uncaught TypeError: Cannot read property 'fn' of undefined. That points ...
Read more >
The ultimate documentation - Parsley
Parsley is a javascript form validation library. It helps you provide your users with feedback on their form submission before sending it to...
Read more >
Parsley - The ultimate documentation - Maison Valentina
Parsley is a javascript form validation library. It helps you provide your users feedback on their form submission before sending it to your...
Read more >
Parsley - The ultimate documentation - tinlab
Parsley, the ultimate frontend javascript form validation library. ... The last loaded file will automatically set the messages locale for ParsleyValidator.
Read more >
Parsley - The ultimate documentation
js minified one. These files and other builds (Remote, Extras..) are available here. Finally, add data-parsley-validate to each ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found