-
-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ESM version of datatables.net works well except when require.js is loaded #199
Comments
I've just made this commit which adds a proper ES module file for DataTables to our distribution files. I'm not entirely happy with this approach is the only thing - specifically the dependencies for the extensions and styling extensions. When using CommonJS or AMD we could have our Bootstrap 5 integration (for example) I need to think about it some more. Any thoughts would be most welcome. |
Hello @AllanJard - thank you very much for this! I agree with you that adding ES modules for DataTables should not be done at the expense of the Datatables extensions. I know very little Javascript so I am afraid the only help I can provide is through testing and feedback, but let me cc @fwouts who suggested to load DataTables as ESM in the By the way, do you have any recommendation on how to load this ESM version? In the example above I was using import $ from "https://esm.sh/[email protected]";
import initDataTables from "https://esm.sh/[email protected][email protected]"; but maybe with your commit I can use a more standard CDN? |
I've updated our nightly server to allow the new mjs file, so you can use: import DataTables from 'https://nightly.datatables.net/js/jquery.dataTables.mjs'; http://live.datatables.net/fedopalo/1/edit I wouldn't recommend depending upon it long term though - the nightly can, does and will change as development progresses. I'd suggest hosting it on your own server if you wanted to use it for production until we finalise how to get ESM working across all of our files. |
Thank you @AllanJard - I can confirm that the nightly build works and that I don't have any issue now when I think I'll wait until you release the next version and then I'll import DataTables from https://cdn.datatables.net/ |
You might be interested in a discussion I've started on the WHATWG HTML repo that stemmed from our discussion here: whatwg/html#7600 . |
Thank you @AllanJard , very interesting discussion indeed... And I am even wondering it what I am seeing in your code snippet, i.e. importing the library from a string, might not help me implement the offline mode in |
I'll close this issue as this has been fixed in the new ES module. If we replace the script above with <script type="module">
import $ from "https://esm.sh/[email protected]";
import dt from "https://cdn.datatables.net/1.12.1/js/jquery.dataTables.mjs";
dt($);
// Display the table
$(document).ready(function () {
$('#table_id').DataTable();
});
</script> then we don't get a conflict with requirejs any more. |
Thank you @AllanJard for the great library!
I am opening this issue (also documented at https://datatables.net/forums/discussion/69066/esm-es6-module-support on the forum) as I would like to use a pure ESM version of datatables.net for my
itables
project (issue #51 there).Currently the ESM version of datatables.net works very well, except when
require.js
is loaded.A sample HTML file that reproduces the issue is below:
Note that the HTML example above works properly when the paragraph that loads
require.js
is removed.The error stack is as follows:
The text was updated successfully, but these errors were encountered: