# Cannot use import statement outside a module

**URL:** <https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306>\
**Category:** Phaser 3\
**Created:** [May 9, 2024, 2:04pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306 "2024-05-09T14:04:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![didisoru](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@didisoru](https://phaser.discourse.group/u/didisoru)\
**Post date:** [May 9, 2024, 2:04pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306/1 "2024-05-09T14:04:25Z")

</div>

I installed phaser in my project directory and i made a “script.mjs” file with “import Phaser from “phaser”;” it give me this error even thou the extension is “mjs”

---

<div class="post-metadata">

**Author:** ![didisoru](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@didisoru](https://phaser.discourse.group/u/didisoru)\
**Post date:** [May 9, 2024, 2:23pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306/2 "2024-05-09T14:23:00Z")

</div>

actually i deleted the line from script.mjs and it gives me the same error and the change is not reflected in error log

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 9, 2024, 8:30pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306/3 "2024-05-09T20:30:28Z")

</div>

> [@Phaser 3 with modules](https://phaser.discourse.group/t/phaser-3-with-modules/13950):
>
> You need only 1 module script in the HTML document, e.g., main.js. That’s the top-level module. That script can import any other modules it needs. \<script src="main.js" type="module"\>\</script\> If you don’t mark this script as a module, you’ll see an error similar to Uncaught SyntaxError: import declarations may only appear at top level of a module In the browser, module specifiers are URLs (unless you use [import maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#importing_modules_using_import_maps)). Relative URLs must start with / or ./ or ../. import { Game } from "ht…

---

<div class="post-metadata">

**Author:** ![didisoru](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@didisoru](https://phaser.discourse.group/u/didisoru)\
**Post date:** [May 10, 2024, 2:38pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306/4 "2024-05-10T14:38:39Z")

</div>

Thanks for the advice ! 🙂 Now i have another error :Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/html”. Strict MIME type checking is enforced for module scripts per HTML spec.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 10, 2024, 4:12pm UTC](https://phaser.discourse.group/t/cannot-use-import-statement-outside-a-module/14306/5 "2024-05-10T16:12:07Z")

</div>

Probably the script URL is wrong.
