Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: A script element with a defer attribute must not have a type attribute with the value module

I have this code in the <head>-section:

<script defer src="./static/js/main.js" type="module"></script>

The validator on validator.w3.org gives me the error: "A script element with a defer attribute must not have a type attribute with the value module."

The javascript works fine and I am trying to understand the reason for the error. What can I do to solve the error?

like image 610
johannes Avatar asked Nov 19 '25 13:11

johannes


1 Answers

I found the answer on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script.

The defer attribute has no effect on module scripts — they defer by default.

The error message is a little bit confusing. It suggests there is something wrong with the type-attribute. It would be a little bit more clear if it would say something like: "A script element with a type attribute with the the value module should not have a defer attribute."

like image 60
johannes Avatar answered Nov 21 '25 03:11

johannes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!