Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phayes0289's avatar

Are there Package Incompatabilities with Vite or Laravel Module Sysems in General?

I have taken a bare-bones Laravel project and have been trying to teach myself how to use Vite. I have tried testing it with numerous packages I use on a regular basis, but I have run into enormous headaches with some of them. For instance.. jQuery, sweetalaert2, chart.js, and jquery-datetimepicker all seem to work. But when I try to add select2 or chosen-js, I get all sorts of errors with jQuery suddenly not being loaded. I have tried everything I know, including making sure jQuery loads first.

Is it worth it to move to Vite? Should I stick with Laravel Mix? Or should I just do it the old-fashioned way by putting the plugins in a public directory? Right now, I am doing it the old-fashioned way, but I thought I would try it the Laravel way.

This is my app.js file that gets broken as soon as I add "import 'chosen-js';" The error occurs on the build file and appears as "Uncaught ReferenceError: jQuery is not defined"

If I remove it and rebuild it, everything works again. Even if I strip is down to just:


import $ from 'jquery';
window.$ = window.jQuery = $;
import 'chosen-js/chosen.css'; // Import Chosen CSS
import 'chosen-js';

I still get the jQuery is undefined error. Very frustrating.

0 likes
4 replies
jlrdw's avatar

I suggest just writing your own and not use any packages.

I use blade, regular javascript, axios js, and server fetched partials. I lean toward popup lookup tables rather than select option. But just my opinion.

https://laracasts.com/discuss/channels/laravel/can-i-redirect-a-get-request-to-a-post-request-for-inertia-partial-reloads?page=1&replyId=905775

https://laracasts.com/discuss/channels/laravel/can-i-redirect-a-get-request-to-a-post-request-for-inertia-partial-reloads?page=1&replyId=905441

As far as vite goes there's a video series on that right here.

RemiM's avatar

If your goal is to build a modern application with up-to-date tools, consider the following:

  • Use Vite for a faster, modern build process.
  • Remove jQuery, as native JavaScript has significantly improved since 2015.
  • Replace outdated or unsupported libraries like select2 or chosen-js with modern alternatives from NPM.
  • Consider switching from Bootstrap to Tailwind CSS, which is now Laravel’s default CSS framework (though keeping Bootstrap is still a valid choice).

A great approach is to start a brand-new project from scratch, using Herd for instance, and see what comes with it. This way, you'll be working with the right tools rather than struggling against outdated or unnecessary ones.

Please or to participate in this conversation.