Browserify and Parsley
See original GitHub issueHi,
I have an issue with Parsley when I’m adding it via Browserify.
Uncaught TypeError: $(...).parsley is not a function
This is my script
var $ = require('jquery');
require('parsleyjs');
$("[data-parsley-validate]").parsley({
trigger: 'change',
errorClass: "parsley-error",
classHandler: function (el) {
return el.$element.closest('.form-item, .form-item--inline, .form-item--icon');
},
errorsContainer: function(pEle) {
var $err = pEle.$element.closest('.form-item, .form-item--inline, .form-item--icon').append();
return $err;
}
});
I tried to use the window object but I got the same error.
I use Gulp with Browserify, others plugins works well with it. But I got the same error with slick carousel, then I used the build they made especially for Browserify and it worked.
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
How to Use ParsleyJS with Browserify - Stack Overflow
I think I can use browserify-shim to put jQuery and ParsleyConfig in the global scope, but I could use some help with the...
Read more >parsley-bundler - npm
Based on a reasonably sized app, containing 1726 modules, 6.5M uncompressed. Built on a 2016 MacBook Pro with 4 physical CPUs. Bundler, Time....
Read more >Parsley.js: 2.3.3 / 2015-09-19 - doxygen documentation
About: Parsley is a simple to use but powerful JavaScript form validation library. Fossies Dox: Parsley.js-2.9.2.tar.gz ("unofficial" and yet experimental ...
Read more >parsley-laravel-extras - npm Package Health Analysis | Snyk
Learn more about parsley-laravel-extras: package health score, popularity, security, maintenance, versions and more.
Read more >Parsley.js - Bountysource
I have an issue with Parsley when I'm adding it via Browserify. Uncaught TypeError: $(...).parsley is not a function. This is my script...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I managed to use it with the ES2015 modules import syntax for those who are interested:
It doesn’t resolve the issue related to jQuery though.
This was blocking one of our projects, and after three hours digging deep in browserify, I think I’ve at least found an explanation for this:
Browserify treats all
require
calls as something to be compiled. This makes jQuery, for all intents and purposes, a compile-time dependency for ParsleyJS when referenced via Browserify-- and it REALLY shouldn’t be!There doesn’t appear to be a way to fix this and still use es2015 syntax. It may be necessary to just check for a global jQuery variable and use that instead of the
require
syntax to get a reference to jQuery.