Skip to content
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

Datatables fails to load as a script when require.js is present #213

Closed
mwouts opened this issue Jun 20, 2022 · 6 comments
Closed

Datatables fails to load as a script when require.js is present #213

mwouts opened this issue Jun 20, 2022 · 6 comments

Comments

@mwouts
Copy link

mwouts commented Jun 20, 2022

This is a follow-up on this comment.

In some cases (and I don't have control on that), require.js is present in my HTML document.
When this is the case I am not able to load datatables as a simple script element.
(I know I could use a require.config file, but I'd prefer not to make an exception on whether require.js is there or not)

A minimal example that reproduces the issue is this one:

<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
<script>
      $(document).ready(function () {
    $('#table').DataTable({});
});
</script>

(the example works when the "require.min.js" library is removed)

Thanks!

@AllanJard
Copy link
Contributor

I've covered some points about this in my comment here, but to keep this topic here - in a Require environment DataTables does not automatically expose itself in the global scope, which I think it typical and correct for AMD modules.

I'm not sure what the correct thing to do here is. Require is loaded, but it isn't being used. If it were used, then it would work. If it weren't loaded, the above would work. It is the combination of the two - Require being loaded, but expecting it to work globally, that is the issue.

I've opened an issue to see if we can get feedback about this from the Require JS folk.

@mwouts
Copy link
Author

mwouts commented Jun 23, 2022

Yes, that's it. Thank you Allan!

@AllanJard
Copy link
Contributor

We've had a reply in that thread now noting:

if require.min.js is loaded in a page, then the assumption is that module loading via require/define are supposed to be used, particularly if the script supports UMD.

So at this time, I won't be making any changes to our UMD to register DataTables globally and with AMD at the same time.

@mwouts
Copy link
Author

mwouts commented Jun 28, 2022

Sure, makes sense... and also I agree that my question (the heterogeneity of the environments in which Jupyter notebooks are rendered) is very specific. Anyway, thank you so much for considering it!

@AllanJard
Copy link
Contributor

On the plus side, I've been making good progress with ES modules recently. Going on to be in holiday next week, but should have something to show after that.

@mwouts
Copy link
Author

mwouts commented Jun 29, 2022

Awesome! Keep me posted... and have a great holiday!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants