When working with JS modules we need to include type="module"
in the <script> element in order to declare the script as a module, for example:
<script type="module" src="theme-script.js"></script>
With WordPress when we enqueue scripts we don’t have the option to add type=”module” but we can use the script_loader_tag to filter the enqueued scripts as in the example gist below: