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:
- [Solved] SyntaxError: Cannot use import statement outside a module
- js: SyntaxError: Cannot use import statement outside a module
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] JS Error: Uncaught SyntaxError: Illegal return statement
- [Solved] Uncaught SyntaxError: The requested module does not provide an export named
- vue Error: Uncaught SyntaxError: Invalid shorthand property initializer
- [Solved] Uncaught SyntaxError: Invalid Unicode escape sequence
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] Uncaught SyntaxError: Unexpected token ‘<‘
- [Solved] Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension
- [Solved] Vue3 Import element UI error: Uncaught TypeError: Cannot read properties of underfined…
- [Solved] component import error is declared in the statement of components
- [Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function
- [Solved] Vue Import swiper.css Error: Module not found…
- Vue-router import Dynamic Module Error [How to Solve]
- [Solved] Uniapp project use vant icon Error: (module build failed from./node_modules/postcss loader/SRC/index)
- [Solved] Vite Error: Failed to load module script: Expected a JavaScript module script but the server…
- Vue Import element-plus Error: Failed to resolve import “element-pluslibtheme-chalkindex.css“ from “src