0

I keep getting uncaught syntaxError: cannot use import statement outside a module

18th Jun 2020, 2:50 PM
Chisom Wopara
4 ответов
+ 1
<script type="module" ></script> Add this: type="module" to your script tag and let me know if it works👍
18th Jun 2020, 3:25 PM
Roni Dey
Roni Dey - avatar
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
18th Jun 2020, 3:03 PM
Seniru
Seniru - avatar
0
Tried it does not work
18th Jun 2020, 3:25 PM
Chisom Wopara
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
27th Feb 2023, 4:48 AM
fostercarly