close

[Solved] SyntaxError: import declarations may only appear at top level of a module [duplicate]

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error SyntaxError: import declarations may only appear at top level of a module [duplicate] in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How SyntaxError: import declarations may only appear at top level of a module [duplicate] Error Occurs?

Today I get the following error SyntaxError: import declarations may only appear at top level of a module [duplicate] in javascript.

How To Solve SyntaxError: import declarations may only appear at top level of a module [duplicate] Error ?

  1. How To Solve SyntaxError: import declarations may only appear at top level of a module [duplicate] Error ?

    To Solve SyntaxError: import declarations may only appear at top level of a module [duplicate] Error 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 in about:config

  2. SyntaxError: import declarations may only appear at top level of a module [duplicate]

    To Solve SyntaxError: import declarations may only appear at top level of a module [duplicate] Error 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 in about:config

Solution 1

I got this on Firefox (FF58). I fixed this with:

  1. It is still experimental on Firefox (from v54): You have to set to true the variable dom.moduleScripts.enabled in about:config

Source: Import page on mozilla (See Browser compatibility)

  1. Add type="module" to your script tag where you import the js file

<script type="module" src="appthatimports.js"></script>

  1. Import files have to be prefixed (.//../ or http:// before)

import * from "./mylib.js"

For more examples, this blog post is good.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment