Jquery-validation: How use with es6 and webpack

Created on 9 Nov 2016  路  4Comments  路  Source: jquery-validation/jquery-validation

Hi, one question. How use this plugin with es6 and webpack.

I have this with fifferent ways of importing:

import 'jquery-validation/src/jquery.validate';
import 'jquery-validation';
Or

require('jquery-validation/src/jquery.validate');
require('jquery-validation');

No option works, in this line the console return:

$("#myform").validate();

"TypeError: $(...).validate is not a function"

Can you help me

Thanks!

Most helpful comment

This seems to work:

import 'imports-loader?define=>false,module.exports=>false!jquery-validation'

This requires the imports-loader plugin for webpack.

yarn add imports-loader --save-dev

All 4 comments

I have no experience with webpack, so cannot help you. sorry for that.

maybe this issue will be resolved with the upcoming release as we updated the UMD support with https://github.com/jzaefferer/jquery-validation/commit/ecf54e04992a8e67422066301a848a40a6144a19.

will close for now, as I cannot help you. please open the question on stackoverflow or even better provide feedback whether the linked changed above fixes your issue.

I solved this by adding this code snippet in my vendor.js file

require('expose-loader?$.fn.validate!jquery-validation');

I have found that manually deleting node-modules/jquery-validation/node-modules/jquery fixes this.
It seems like jquery-validate is adding itself to it's own copy of jquery, and that's the the copy that ends up in your ES6 app.
This workaround is not satisfactory since it requires manual intervention anytime you run npm install.

This seems to work:

import 'imports-loader?define=>false,module.exports=>false!jquery-validation'

This requires the imports-loader plugin for webpack.

yarn add imports-loader --save-dev

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kodeo picture kodeo  路  7Comments

ricardopolo picture ricardopolo  路  8Comments

iamandycohen picture iamandycohen  路  5Comments

BenjaminHoegh picture BenjaminHoegh  路  7Comments

lucasgonze picture lucasgonze  路  7Comments