Import Parsley.js with es6 does not register plugin
See original GitHub issueWhat kind of issue is this? (put ‘x’ between the square brackets)
-
Question. This issue tracker is not the place for questions. If you want to ask how to do something, or to understand why something isn’t working the way you expect it to, use http://stackoverflow.com/questions/ask . Provide working code, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101. We monitor the tag
parsley.js
. -
[ X] Bug report. If you’ve found a bug, you must provide a minimal example in a CodePen, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101 .
-
Feature Request. Make sure there’s no good way to do what you want first; consider asking on http://stackoverflow.com/questions/ask first.
Sadly this can be reproduced on codepen. But it is not hard to reproduce. When adding parsley natively using import (in supported browsers like Chrome or Safari) does not registers the plugin in the jQuery instance.
Take this main.js
file:
import './libs/jquery/jquery-3.3.1.min.js';
import './libs/jquery/jquery-ui-1.12.1/jquery-ui.min.js';
import './libs/parsley-2.8.1/parsley.js';
It Throws the error:
Uncaught TypeError: Cannot read property ‘jQuery’ of undefined
while jQueryUI
does work as expected.
The error comes fron somewhere around this at the beginning from parsley.js
:
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
global.parsley = factory(global.$)
My workaround is adding a global verification
global = (global) ? global : window;
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) : typeof define === 'function' && define.amd ? define(['jquery'], factory) : global.parsley = factory(global.jQuery);
I do not dare to make a PR because I am not familiar with the Parsley source and I am not quite sure what “global” is suppose to be (Also I can no find the source for that part 😞 )
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8
Top GitHub Comments
hi, I’m using
jQuery
fromajax.googleapis.com
cdn and build my scripts withwebpack
. So I’ve solved this issue for me by addingjQuery
inexternals
section in webpack configand import parsley
Thanks @marcandre using
../../path/to/my/jquery.js
it works.Would be nice if we could use the
dist
version also with import likejquery-ui
.