SyntaxError: Cannot use import statement outside a module
Add type="module" inside the script tag
Add "type": "module" to your package.json
If you are working on Node.js or react applications and using import statements instead of require to load the modules, then ensure your package.json has a property "type": "module" as shown below.
Use the extension .mjs in your files
If you are using node application and want to use the import statement, then you will also get the " Cannot use import statement outside a module " error. It is because ES6 import and export statements are not support in node by default. In order to solve this problem, use the extension .mjs in your files and use this command to run the file.
Use import by required
In some cases, you may have to use both import and require statements to load the module properly.