const { mix } = require('laravel-mix');
mix.js([
'public/admin/js/jquery.js',
'public/admin/js/bootstrap.min.js',
],'production/js/final.js');
But when i include final.js i got the following error
Uncaught Error: Bootstrap's JavaScript requires jQuery
I've installed the jquery with npm install jquery --save but still i got above error
In app.js add
window.$ = window.jQuery = require('jquery')
@Shamoncushbu I had this problem before. The problem solved just by using scripts instead of js for vanilla JS "as mentioned in docs"
For all the future googlers, I solved the problem with
mix.autoload({
jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"]
});
EDIT: Add this before all your calls to mix.js() and mix.scss() etc.
@ProExpertProg
It works! Thank you!!!
This solution worked for me:
mix.autoload({
jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"]
});
thought I would like to know why the following one did not.
window.$ = window.jQuery = require('jquery')
Thanks.
@gocanto because bootstrap is loaded separately (in another closure) and jQuery has to be injected by webpack. mix.autoload(....) tells mix where does jQuery need to be injected, so whenever webpack finds $ or window.$ etc., it will inject jQuery.
Oh ok. Thanks a lot
@ProExpertProg In what file did you add your mix.autoload? I'm using a creat-react-app and getting the same error as the trend here.
webpack.mix.js I'm pretty sure.
>
Loaded from CDN before main.js for legacy Elixir...
Not working for me added
mix.autoload({
jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"]
})
in webpack.mix.js
Still getting error http://prntscr.com/s9nld6
@bilalnaseer did you figure it out?
Most helpful comment
For all the future googlers, I solved the problem with
EDIT: Add this before all your calls to
mix.js()andmix.scss()etc.