I believe I've set everything up correctly, but I'm getting an odd issue with Webpack.
Consider this simple app.ts
file:
'use strict';
import $ = require('jquery');
import 'jquery-ui';
$(function() {
$( "#sortable" ).sortable();
});
Everything compiles fine, but when the site is run it complains that the Uncaught TypeError: $(...).sortable is not a function
. (sortable
is a jQuery UI function).
Everything works fine when I instead link to a CDN hosted version of jQuery and jQuery UI, but it doesn't work when I use JS modules and Webpack. Why is this?
Why is the jQueryUI function sortable()
not recognized?
The problem is that jQuery UI normally automatically pulls in the components it needs (which is why it works when it's linked via a CDN), but that doesn't work when it's imported as a module (like with Webpack).
Thankfully as of jQuery UI 1.11 you can manually pull in any extra components you need like so:
'use strict';
import $ = require('jquery');
require('jquery-ui');
require('jquery-ui/ui/widgets/sortable');
require('jquery-ui/ui/disable-selection');
etc.
Here's some official documentation explaining this further.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With