How to Resolve ”Uncaught Syntaxerror: Cannot Use Import Statement Outside a Module”?
To resolve the "Cannot use import statement outside a module" error for NPM/NodeJS, include "type":"module" in the package.json file:
{
"name": "...",
// ...
"type": "module",
// ...
}
If importing directly from the browser, add type="module" to the HTML script tag
<!-- Error -->
<script src="script.js"></script>
<!-- Fixed -->
<script type="module" src="script.js"></script>