SyntaxError: Cannot use import statement outside a module #130799
-
BodyBasically I have an html and two js files and from this html file I call one of these js files:
hello.js:
Help!!!! Guidelines
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This problem is caused by the fact that JavaScript modules require a specific way to be loaded into HTML files. To use import and export statements, you need to ensure that your script is treated as a module. You can do this by adding the type="module" attribute to your <script> tag in the HTML file. So when importing the script into HTML it would look like this👍: It even seems like this has already been discussed here on the github community |
Beta Was this translation helpful? Give feedback.
This problem is caused by the fact that JavaScript modules require a specific way to be loaded into HTML files. To use import and export statements, you need to ensure that your script is treated as a module. You can do this by adding the type="module" attribute to your <script> tag in the HTML file.
So when importing the script into HTML it would look like this👍:
<script type="module" src="script.js"></script>
Result:
It even seems like this has already been discussed here on the github community