Solving the Uncaught SyntaxError: Cannot use import statement outside a module
One of the most common JavaScript error messages since the introduction of the ES6 module system is:
Uncaught SyntaxError: Cannot use import statement outside a module
This error is not directly related to react, vue, angular, firebase, typescript, node error but a basic JavaScript error that was introduced with the ES6 module system.
Node.js solution
If you are using node then add the following entry to your packages.json
file: "type": "module"
HTML solution
If you want to import a JavaScript module directly into your HTML file using the script
tag then extend it with the type
attribute and set it's value to module
.
<script type="module" src="main.js"></script>