Uncaught SyntaxError: Cannot use import statement outside a module

Uncaught syntax error: cannot use import statement outside a module & lt; analysis and solution

Error message:

Error analysis:

In HTML web page, browser loads JavaScript script through script tag. Since the default language of browser scripts is JavaScript, type = “application/JavaScript” can be omitted. We learned from the error report that the import statement cannot be used outside the module, because the loading of the module implements ES6 syntax. Therefore, when the browser loads the HTML file, it is necessary to add the attribute of type = “module” to the script tag.

terms of settlement:


Read More: