Error: [vite]: Rollup failed to resolve import "datatables.net/js/jquery.dataTables"

Error: [vite]: Rollup failed to resolve import "datatables.net/js/jquery.dataTables"

cmpluscmplus Posts: 60Questions: 13Answers: 0

[vite]: Rollup failed to resolve import "datatables.net/js/jquery.dataTables" :

good morning, I use laravel 10 with datatables, my app.js is this, everything was working now but when I execute the npm run build command I receive this error message and the tables present in laravel disappear, what should I do to solve it?

app.js

import * as bootstrap from 'bootstrap';
window.bootstrap = bootstrap;
import 'laravel-datatables-vite';

import jQuery from 'jquery';
window.$ = jQuery;

import moment from "moment";
window.moment = moment();

import Editor from '@datatables.net/editor-dt';
import 'datatables.net-editor-bs5/js/editor.bootstrap5';
import 'datatables.net-bs5/js/dataTables.bootstrap5';
import 'datatables.net-select-bs5/js/select.bootstrap5';
import 'datatables.net-searchpanes/js/dataTables.searchPanes';
import 'datatables.net-searchpanes-bs5/js/searchPanes.bootstrap5';
import 'datatables.net-responsive-bs5/js/responsive.bootstrap5';
import 'datatables.net-buttons-bs5/js/buttons.bootstrap5';
import 'jquery/dist/jquery';
import 'datatables.net/js/jquery.dataTables';
import 'datatables.net-select/js/dataTables.select';
import 'datatables.net-rowgroup-bs5/js/rowGroup.bootstrap5.js';
import 'bootstrap/dist/js/bootstrap.bundle';
Editor(window, $);

Answers

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin
    'datatables.net/js/jquery.dataTables'
    

    doesn't exist. Not as of v2 anyway - it was updated to be just dataTables.js. Why are you importing the file names rather than just using the module and allowing it to auto resolve?

    import DataTable from 'datatables.net-bs5';
    import 'datatables.net-select-bs5';
    import 'datatables.net-rowgroup-bs5';
    

    Allan

  • cmpluscmplus Posts: 60Questions: 13Answers: 0

    @allan thanks for the reply, when I delete that line from the app.js file the table disappears, I have no idea how that line ended up there, and I don't understand why if I delete it the tables stop working

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    Without being able to see it, I don't know, but you could try changing it to datatables.net/js/dataTables (assuming you have v2 of DataTables installed, which I guess you do based on the error). You might want to check that all your DataTables dependencies are up to date to the latest versions.

    Allan

Sign In or Register to comment.