SyntaxError: import declarations may only appear at top level of a module [duplicate]
Solution 1:
I got this on Firefox (FF58). I fixed this with:
- It is still experimental on Firefox (from v54):
You have to set to true the variable
dom.moduleScripts.enabled
inabout:config
Source: Import page on mozilla (See Browser compatibility)
- Add
type="module"
to your script tag where you import the js file
<script type="module" src="appthatimports.js"></script>
- Import files have to be prefixed (
./
,/
,../
orhttp://
before)
import * from "./mylib.js"
For more examples, this blog post is good.