I need to know why when I use onclick attribute in HTML file it works fine but when I change the script tag to be module id doesn't work and gives me this error main is not defined when I click the button
<!--index.html-->
<body>
<button onclick="main()">test</button>
<script type="module" src="./index.js"></script>
</body>
function main() {
const newDev = document.createElement("p");
newDev.textContent = "function works well";
document.body.appendChild(newDev);
}