I struggle using Laravel Mix and DataTables. The issue I have is that when I compile down my .js-files etc., each time I would then visit a page that would execute a jQuery datatable, the follwoing error is thrown:
The error is:
jQuery.Deferred exception: $(...).DataTable is not a function TypeError: $(...).DataTable is not a function
Uncaught TypeError: $(...).DataTable is not a function
From what I understand, $(...).DataTable
is not a global variable, but how can I make sure that it is accessible "on a global scope" / within my app?
The following is my setup:
app.js
import jquery from 'jquery/dist/jquery.slim'
import 'bootstrap-sass'
import 'datatables.net';
import dt from 'datatables.net-bs';
window.$ = window.jQuery = jquery;
webpack.mix.js
mix
.js('resources/assets/admin/js/app.js', 'js/')
.extract([
'jquery', 'bootstrap-sass', 'datatables.net', 'datatables.net-bs'
])
.autoload({
jquery: ['$', 'window.jQuery', 'jQuery', 'jquery'],
DataTable : 'datatables.net-bs'
})
Any idea would be highly appreciated.
var $ = require( 'jquery' ); require( 'datatables.net-bs' )( window, $ )
– Philippicvar $ = require( 'jquery' ); require( 'datatables.net' )( window, $ );
– Philippicimport $ from 'jquery';
– Philippicimport $ from 'jquery-slim'
. I missed that's slim version – Philippic