Skip to content
JS
JavaScript error

SyntaxError

The JavaScript exception "import declarations may only appear at top level of a module" occurs when an import declaration is not at the top level of a module. This might be because the import declaration is nested in other constructs (functions, blocks, etc.), or more often because the current file is not treated as a module.

Reference entryJavaScriptFetched
SyntaxError: Cannot use import statement outside a module (V8-based)
As listed by MDN Web Docs
SyntaxError: import declarations may only appear at top level of a module (Firefox)
As listed by MDN Web Docs
SyntaxError: Unexpected identifier 'x'. import call expects one or two arguments. (Safari)
As listed by MDN Web Docs
Category
SyntaxError
Severity
error
Runtime
both
or press Cmd/Ctrl + Enter. The text is only sent to this site to match it.
Source: MDN Web Docs. Data fetched 2026-09-25T01:48:37.273Z.