[Solved] Uncaught SyntaxError: Cannot use import statement outside a module

1. Error description

Uncaught SyntaxError: Cannot use import statement outside a module

2. Error reason

  Defines a JavaScript file, declares several variables, and uses modularity to export the variables

Let name = “Zhang Hua”
let age = 23
let sex = “female”

Export {name, age, sex}
then, import directly in the page file; Open the browser to access the page, and an error appears on the console

3. Solution

  Need to add the attribute type="module" to the script tag

Read More: