Scene created as class error: Cannot use import statement outside a module

I am struggling with scenes. I found this scene tutorial which supposed to teach how to create every scene as a class, however when I tried to implement it I got the error:

Uncaught SyntaxError: Cannot use import statement outside a module

This is my code…

HTML:
< html>
< head>
< script src=“lib/phaser.min.js”>
< script src=“Game.js”>
< /head>
< body>
< /body>
< /html>

Game.JS:
import StartScene from “StartScene.js”;

var startScene = new StartScene();

var config = {
  type: Phaser.AUTO,
  width: 1024,
  height: 768,
};
var game = new Phaser.Game(config);

game.scene.add("startScene", startScene);
game.scene.start('startScene');

StartScene.JS
class StartScene extends Phaser.Scene {

    constructor () {
        super({key: "startScene"});
    }
    
    init() {
    }
    
    preload() {
    }
    
    create() {
    }
    
    update() {
    }
}

export default StartScene;

Any idea of what am I doing wrong?

Thanks!

Change to

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

And imports like

import StartScene from "./StartScene.js";
1 Like

Thank you very much, Samme! It definetively did the trick!