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

felipesmendes's avatar

Import Select2 installed by npm and use in laravel

I'm trying to import select2 in my project but i'm gotting this error in the view:

jquery-3.5.1.min.js:2 Uncaught TypeError: $(...).select2 is not a function
    at HTMLDocument.<anonymous> (create:764)
    at e (jquery-3.5.1.min.js:2)
    at t (jquery-3.5.1.min.js:2)

I runned npm install select2

then added the require in my app.js

require('./bootstrap');

require('alpinejs');
require('jquery');
require('datatables.net');
window.ApexCharts = require('apexcharts');
window.Swal = require('sweetalert2')
require('select2');

After that I runned npm run dev and got the error when accesss the view.

What I'm doing wrong?

0 likes
3 replies
DYS's avatar

Wow.Thank you ,It worked for me .

1 like

Please or to participate in this conversation.