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.

Browserify and Parsley

See original GitHub issue

Hi,

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:open
  • Created 7 years ago
  • Reactions:4
  • Comments:11

github_iconTop GitHub Comments

7reactions
LeKangouroocommented, Dec 13, 2016

I managed to use it with the ES2015 modules import syntax for those who are interested:

import Parsley from 'parsleyjs';

// NOTE: Parsley is not a constructor, therefore new Parsley() doesn't work.
const validator = new Parsley.Factory(formElement, options);

console.log('is valid', validator.isValid());

It doesn’t resolve the issue related to jQuery though.

1reaction
bajaxcommented, Jun 26, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

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