Datatable Buttons : Cannot read properties of undefined (reading 'defaults')

Datatable Buttons : Cannot read properties of undefined (reading 'defaults')

cartooncartoon Posts: 4Questions: 0Answers: 0

Hello,
I'm using datatable with some additionnal plugins and Webpack to bundle all my assests.

I'm importing every needed plugins as follow :

    const $ = require('jquery');
    global.$ = global.jQuery = $;
    import 'datatables.net-bs5';
    import 'datatables.net-bs5/css/dataTables.bootstrap5.min.css';
    import 'datatables.net-buttons-bs5';
    import 'datatables.net-buttons/js/buttons.html5.js';
    import 'datatables.net-buttons-bs5/css/buttons.bootstrap5.min.css';
    import 'datatables.net-plugins/buttons/button.download.min.js';
    import 'datatables.net-select-bs5';
    import 'datatables.net-select-bs5/css/select.bootstrap5.min.css';
    import 'datatables.net-datetime';
    import 'datatables.net-datetime/dist/dataTables.dateTime.min.css';
    import 'datatables.net-plugins/sorting/datetime-moment.js';
    import 'datatables.net-searchbuilder-bs5';
    import 'datatables.net-searchbuilder-bs5/css/searchBuilder.bootstrap5.min.css';

But when i try to run my application, i've got the following error :

Uncaught TypeError: Cannot read properties of undefined (reading 'defaults') buttons.bootstrap5.mjs:13

I found this https://datatables.net/forums/discussion/71921 where it point that i should import datatables first but i did it and still not working.

Also, i'm initializing my datatable as follow :

$('#dtID').DataTable({
 ....
});

What am i missing ?

Thanks for your help

Replies

  • cartooncartoon Posts: 4Questions: 0Answers: 0

    I'm adding packages versions :

            "datatables.net-bs5": "2.3.2",
            "datatables.net-buttons-bs5": "3.2.3",
            "datatables.net-datetime": "^1.5.6",
            "datatables.net-fixedcolumns-bs5": "4.0.2",
            "datatables.net-fixedheader-bs5": "3.3.2",
            "datatables.net-plugins": "^2.3.0",
            "datatables.net-responsive-bs5": "2.5.0",
            "datatables.net-searchbuilder-bs5": "^1.8.3",
            "datatables.net-select-bs5": "^3.0.1",
            "jquery": "^3.7.1",
    
  • allanallan Posts: 65,056Questions: 1Answers: 10,772 Site admin

    I've just tried creating an example and it appears to work okay: https://stackblitz.com/edit/hv7ntjs6?file=package.json,src%2Fmain.ts .

    I've got it using Vite rather than Webpack there, simply because it was a lot easier to setup! Perhaps you can link to a minimal repo or Stackbltiz example showing the issue so I can help to debug it?

    Allan

  • cartooncartoon Posts: 4Questions: 0Answers: 0

    Thanks for your reply,

    I edited your link (i'm on my way to make a more suitable exemple) as follow :

    "datatables.net-bs5": "2.3.2" instead of "datatables.net-bs5": "^2.3.3",
    "datatables.net-buttons-bs5": "3.2.3" instead of "datatables.net-buttons-bs5": "^3.2.4",
    "datatables.net-select-bs5": "3.0.1"instead of datatables.net-select-bs5": "^3.1.0",
    "jquery": "3.7.1" instead of "jquery": "^3.7.0"

    I omitted fixed header, fixed column and plugin but i still reproduce the error :

    Could it be version related ?

  • allanallan Posts: 65,056Questions: 1Answers: 10,772 Site admin

    It is possible, although I can't immediately think of what would cause that.

    If you update your versions to the latest, like in my example (minus jQuery), does it then work?

    Allan

  • cartooncartoon Posts: 4Questions: 0Answers: 0

    I update all my datatable.net-* packages and it's working !
    Here's the used versions

    "datatables.net-bs5": "2.3.3",
    "datatables.net-buttons-bs5": "3.2.4",
    "datatables.net-datetime": "1.5.6",
    "datatables.net-fixedcolumns-bs5": "5.0.4",
    "datatables.net-fixedheader-bs5": "4.0.3",
    "datatables.net-responsive-bs5": "3.0.6",
    "datatables.net-plugins": "2.3.2",
    "datatables.net-select-bs5": "3.1.0",
    "datatables.net-searchbuilder-bs5": "1.8.3",
    "jquery": "3.7.1"
    

    Thanks for your help.

  • allanallan Posts: 65,056Questions: 1Answers: 10,772 Site admin

    Awesome - thanks for letting me know.

    Allan

Sign In or Register to comment.