0
I keep getting uncaught syntaxError: cannot use import statement outside a module
4 ответов
+ 1
<script type="module" ></script>
Add this: type="module" to your script tag and let me know if it works👍
0
So there's the answer, you are trying to do imports when you are not inside the module - well I just said the exact thing
0
Tried it does not work
0
This error occurs when you try to use an import statement outside a module. This can happen in different cases depending on whether you're working with JavaScript on the server-side with Node.js , or client-side in the browser. There are several reasons behind this error, and the solution depends on how you call the module or script tag. Solutions:
Add type="module" inside the script tag
Add "type": "module" to your package.json
Use the extension .mjs in your files
Use import by required
If you're still getting the error even though you're using import in a module file, make sure that your JavaScript environment supports modules. Some older browsers and Node.js versions do not support modules natively, and you may need to use a module bundler like Webpack or rollup.js to transform your module code into a format that can be used in your environment.
http://net-informations.com/js/err/import.htm