F.Ghost
F.Ghost

Reputation: 23

Why i cant import modules in JS

why i cant import my class when i am using the app.js in my html file?

In the console is always Cannot use import statement outside a module

Html snippet

<!-- Scripts -->
<!-- Bootstrap -->
<script src="assets/plugins/bs/bs.js"></script>
<!-- APP -->
<script src="assets/js/SmashTheHamster.js"></script>
<script src="assets/js/Elements.js"></script>
<script src="assets/js/Session.js"></script>
<script src="assets/js/app.js"></script>

code in app.js (there is this error Cannot use import statement outside a module) and yes i exported my modules with export defaut MODULE

import elements from "./Elements";
import SmashTheHamster from "./SmashTheHamster";

thx for help

Upvotes: 0

Views: 389

Answers (1)

MVT KVM
MVT KVM

Reputation: 198

You have to specify the type of the script tag using type="module"

Upvotes: 1

Related Questions