elbsurfer's avatar

Script tag type=module needed?

Hello, I was trying to use Glide.js this evening and did the following after installing glide.js via npm.

Within my resources/js/app.js file I have this contents:

require('./bootstrap');

import Glide from '@glidejs/glide'
new Glide('.glide').mount();

My webpack.mix.js file looks like this:

mix.copyDirectory('resources/img', 'public/img')
    .js('resources/js/app.js', 'public/js')
    .version();

When I now load the frontend, my slider does not work - it throws an JS error : [Glide warn]: Root element must be a existing Html node

When I change my script tag from:

<script src="{{ mix src='js/app.js' }}"></script>

To

<script src="{{ mix src='js/app.js' }}" type="module"></script>

It works - but is this really necessary? I have never read about type=module in combination with mix.

0 likes
1 reply
elbsurfer's avatar
elbsurfer
OP
Best Answer
Level 2

I figured it out and use defer in the script tag now. My error was triggered by a race condition and it seems that type=module does some kind of deferring as well.

Please or to participate in this conversation.