Broken Demo Game

Hello,

I’m just getting started with Phaser so I’m sure something wasn’t set up right. I’ve installed Phaser to the best of my knowledge, got the mongoose server running and running the development server.

I used the create-phaser-game app to create a basic game using the Memory Card Game as the template. I did what the readme said to do and ran ‘npm install’ in the root directory of the game and started the development server.

Going through the tutorial, the next step is to simply check that the demo project even comes up, so I hit the play button, only to be greeted with an empty webpage. Hitting F12, I see the following error, and can’t figure out how to proceed and searching for the error isn’t providing me much help that I can decipher:

Uncaught TypeError: Failed to resolve module specifier “phaser”. Relative references must start with either “/”, “./”, or “…/”.

:wave:

You may have 2 separate web servers running.

Did you do npm run dev from here? After that the terminal should show

Local:   http://localhost:5173/

and that’s what you open in the browser.

1 Like

Hi @samme,

Ah okay, yes I pasted the address from the server into the browser and the game immediately came up! Yay!

I neglected to mention that I’m using the Phaser Editor (v4.5.1) and in the documentation I was following for it, it said to run the game by hitting the play button in the editor, which is what brings up the broken web page. Regardless of whether or not I have the local dev server started, I get the same error in the web page that’s launched by hitting the play button in the editor.

I don’t mind using the local server address to run the games from, but I’m wondering, did I do something wrong here or is this a bug with the play button?

I don’t know much about how Phaser Editor works. :slightly_frowning_face:

1 Like

For the Phaser Editor, you will still need a local dev server, but the tool has the ability to launch this for you. However, for any projects that are using packages installed via npm, the editor will not know how to compile this code, which results in the error you are seeing.

To fix this, you need to provide a configuration file to Phaser Editor, that will tell the editor how to run your project locally.

If you create a file called phasereditor2d.config.json in the root of your project, and add the following code:

{
    "plugins": [],
    "scripts": [],
    "skip": [
        "dist"
    ],
    "playUrl": "http://localhost:5173"
}

Now, when you hit the play button, you should be prompted to start the dev server, and once this is done the browser should show your game.

2 Likes

Thank you @scottwestover! This did the trick, and I can now run the game from the phaser editor directly.