xxxxxxxxxx
package.json
{
// ...
"type": "module",
// ...
}
xxxxxxxxxx
//make sure whether include type="module" in script tag
<script type="module" src="module.js"></script>
xxxxxxxxxx
// Fix 1
Change .js files to .cjs
// Fix 2
Add "type": "module" to package.json
xxxxxxxxxx
//Add type=module to your index.js script tag (not just the package script tag)
<script type="module" src="./index.js"></script>
you have to add the type attribute with the value module when you load the script, like this:
xxxxxxxxxx
<script type="module" src="./file.js"></script>
xxxxxxxxxx
[Solved] “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6