Datatables not working with WebPack
Datatables not working with WebPack

There are several other posts that have to do with WebPack and Datatables and none of them help my present situation.
First of I, I get datatables through download. I have to do this because I am using the editor and downloading is apparently the only way to use this.
As part of the download I get 2 files: datatables.js and datatables.css (and their .min counterparts).
So I import these files into my app.js...
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.scss';
import 'jquery';
import 'bootstrap';
import './datatables/datatables.css';
import DataTables from './datatables/datatables.js'
Webpack then compiles with the following errors...
Module build failed: Module not found:
"./assets/datatables/datatables.js" contains a reference to the file "datatablese "datatables.net".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/datatables/datatables.js" contains a reference to the file "datatables.net-bs5".
This file can not be found, please check it for typos or update it if the file got moved.
"./assets/datatables/datatables.js" contains a reference to the file "datatables.net-editor".
This file can not be found, please check it for typos or update it if the file got moved.
So what is going wrong here? It seems that webpack is looking for a bunch of files that weren't downloaded.
Answers
You appear to be using npm (or yarn, or similar) for jQuery and Bootstrap, but not DataTables. Is there a reason for that? Given you are using modules and a package manager, I would definitely recommend you do that. Click the "NPM" tab at the bottom of the download builder page.
That said, you can use a local file but the .js file is a UMD (i.e. browser, AMD or CommonJS), but you are using it as an ES Module there. That can work, depending on the Webpack setup, but I think it takes extra configuration.
You could try using the
.mjs
file which is the ES Module loader version. But as I say, just use the npm modules unless there is a good reason not to.Allan
I would love to use NPM for datatables. However I want to use the editor. To use the editor I need to use the download. I think. The documentation is very muddled on this point. Apparently in the past you could use NPM to use the editor with some kind of secret key, but apparently no longer.
How do you use the editor with NPM?
Assuming that NPM is a non-starter, what is the "extra configuration" I need? Where is the ".mjs" file. I did not get that in the download.
The webpack setup I am using was configured by symfony webpack encore. So nothing special. Should be a common setup I would think.
I don't think it is that muddled is it? The instructions are in the manual here and in the NPM tab of the download builder.
You can certainly use Editor with your package manager!
Allan
Ok. I got this working. I think. I found the NPM Dr. Who Secret Handshake to install the Editor from a private repository.
Please share so others can benefit from your learning. What steps did you take?
Kevin
It will most likely be this part where you have to tell npm which repository to get Editor from.
False alarm. Still not working. So when I try to create the Editor, I get...
Error: No Bootstrap library. Set it with
DataTable.use(bootstrap);
So in my code I have...
This is symfony webpack encore, so in my app.js. I have...
// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.scss';
import 'jquery';
import 'bootstrap';
import DataTable from 'datatables.net-bs5';
import Editor from '@datatables.net/editor-bs5';
import DateTime from 'datatables.net-datetime';
So here is my package file...
So what am I doing wrong?
Try putting it before you initalise the Editor instance.
This is when the download builder suggests to use if you select Bootstrap (both style and library), DataTables and Editor:
The slightly different
use
line is becase DataTables 2.2 and Editor 2.4 can work together to make that slightly easier.Allan