Laravel-mix: Bootstrap's JavaScript requires jQuery with bootstrap build

Created on 19 May 2017  路  12Comments  路  Source: JeffreyWay/laravel-mix

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

Most helpful comment

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.

All 12 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeffreyWay picture JeffreyWay  路  60Comments

tillkruss picture tillkruss  路  39Comments

rn1ee picture rn1ee  路  138Comments

jericopulvera picture jericopulvera  路  48Comments

HerrTxbias picture HerrTxbias  路  107Comments