OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Laravel 11 mix to vite : Uncaught TypeError: $ is not a function

  • Thread starter Thread starter Rémi Tardif
  • Start date Start date
R

Rémi Tardif

Guest
I'm using Laravel 11 mix and i have a problem with Alpine wich is load 2 times when i connect on my website in local. If it's possible, i prefer to stay in mix i already tried to go on laravel vite but i have a problem with my Jquery and Bootstrap. here is the error i have :

livewire.js?id=87e1046f:9882 Detected multiple instances of Alpine running

and here is my code :

app.js :

Code:
import Alpine from 'alpinejs';

window.Alpine = Alpine;

Alpine.start();

require('./sb-admin-2');

bootstrap.js

Code:
window._ = require('lodash');

try {
    //window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');
    //require('jquery.easing')(window.jQuery);

    require('bootstrap');
} catch (e) {
}

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

and finaly my webpack.mix.js :

Code:
const mix = require('laravel-mix');
require('laravel-mix-purgecss');


mix.webpackConfig({
    stats: {
        children: true
    }
});

mix.js("resources/js/app.js", "public/js")
    .js("resources/js/bootstrap.js", "public/js")
    .sass( "resources/sass/app.scss", "public/css")
    .purgeCss(
);

I saw on forum that is possible to solve it by going on laravel vite but do u know if there is other options ?

I have thoses versions :

Code:
    "@fortawesome/fontawesome-free": "^5.15.4",
    "alpinejs": "^3.8.1",
    "bootstrap": "^4.6.1",
    "jquery": "^3.6.0",
    "npm": "^10.8.1",
    "popper.js": "^1.16.1"

<p>I'm using Laravel 11 mix and i have a problem with Alpine wich is load 2 times when i connect on my website in local. If it's possible, i prefer to stay in mix i already tried to go on laravel vite but i have a problem with my Jquery and Bootstrap. here is the error i have :</p>
<p>livewire.js?id=87e1046f:9882 Detected multiple instances of Alpine running</p>
<p>and here is my code :</p>
<p>app.js :</p>
<pre><code>import Alpine from 'alpinejs';

window.Alpine = Alpine;

Alpine.start();

require('./sb-admin-2');
</code></pre>
<p>bootstrap.js</p>
<pre><code>window._ = require('lodash');

try {
//window.Popper = require('popper.js').default;
window.$ = window.jQuery = require('jquery');
//require('jquery.easing')(window.jQuery);

require('bootstrap');
} catch (e) {
}

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

</code></pre>
<p>and finaly my webpack.mix.js :</p>
<pre><code>const mix = require('laravel-mix');
require('laravel-mix-purgecss');


mix.webpackConfig({
stats: {
children: true
}
});

mix.js("resources/js/app.js", "public/js")
.js("resources/js/bootstrap.js", "public/js")
.sass( "resources/sass/app.scss", "public/css")
.purgeCss(
);

</code></pre>
<p>I saw on forum that is possible to solve it by going on laravel vite but do u know if there is other options ?</p>
<p>I have thoses versions :</p>
<pre><code> "@fortawesome/fontawesome-free": "^5.15.4",
"alpinejs": "^3.8.1",
"bootstrap": "^4.6.1",
"jquery": "^3.6.0",
"npm": "^10.8.1",
"popper.js": "^1.16.1"
</code></pre>
 

Latest posts

Top