Torben
Torben

Reputation: 5494

JavaScript (glide.js) - Laravel Mix "type=module" needed and why?

I am using a Laravel application and Laravel Mix for asset building.

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 filed which is compiled by Laravel Mix, 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. Is this always necessary once the main js has "import" statements?

Upvotes: 1

Views: 883

Answers (0)

Related Questions