Uncaught TypeError: Super expression must either be null or a function

app.js

import {Game} from './Game'
//Let go
new Game(700,450, 'phaser')

Game.js

import {Lobby} from "./states/Lobby"
export class Game extends Phaser.Game {
    
    // Initialize Phaser
    constructor(width, height, container) {
      super(width, height, Phaser.AUTO, container, null)        
      // set up game state [name, class, autostart]
      this.state.add("lobby", Lobby, false)

    }
  
}

Lobby.js

import { createLabel } from "../common/labels"
export class Lobby extends Phaser.State {

    create() {
        const label = createLabel(this,"Hello world")
        label.anchor.setTo(0.5)
    }
}

labels.js

const DEFAULT_STYLE = {font: "65px Arial", fill: "#ffffff" }
    // createLabel :: State -> String -> Object -> Sprite
    export const createLabel = (state, message, style = DEFAULT_STYLE) => {
    const {centerX, centerY} = state.world
    return state.add.text(centerX, centerY, message, style)
}

When I run I got the error message like this:

Uncaught TypeError: Super expression must either be null or a function
What do I am missing here?

That’s Phaser 2 code. Which version of Phaser are you loading?

Thanks @Telinc1, I am using Phaser v3.24.1 (WebGL | Web Audio).

Code meant for Phaser 2 will not work in Phaser 3. If you’re following a tutorial, you should either find another tutorial for Phaser 3 or switch your version to Phaser 2 or Phaser CE.

@Telinc1, thanks for you answer.
Yes, you are right , I am following the tutorial which is from here , the code is using too old version, and I need to use the new one.

could you help to advice any change I need in order to make the code work with version 3.

Phaser 2 and Phaser 3 have fundamentally different APIs, even if they look similar on the surface. Porting code from Phaser 2 to Phaser 3 often requires good knowledge of both frameworks. I recommend that you either find a different tutorial or switch to Phaser CE (which is a community-supported fork of Phaser 2).

1 Like

okay @Telinc1, I will check another tutorial with version 3 .