Issue with Phaser file not running - comes up with Microsoft JS Compilation error

I am just starting with Phaser, I have installed Phaser’s JS files on my computer through GitHub. However, when I have tried to run the Phaser.js file for my game, it shows the following error:

Because of this I don’t think Phaser is actually running when I write in my code, because the console comes up with an Uncaught TypeError for .add(), saying that game.state.add() is undefined:

(function(){
    game=Phaser.Game(window.innerWidth* window.devicePixelRatio,window.innerHeight*window.devicePixelRatio,Phaser.AUTO);
    game.state.add("Boot",Boot);
    game.state.add("Preload",Preload);
    game.state.add("NightlyNeighbours1WithPhaser",Main); 

Also, things which are specific to Phaser are coming up with unresolved functions/methods/variables (for example):

create:function(){
    this.game.physics.startSystem(Phaser.Physics.ARCADE);

WebStorm underlines the method .startSystem(), and says that the function or method is unresolved, In addition, it also underlines the ARCADE and says the variable is unresolved.

Therefore, my question: is the issue with my programming or with the phaser.js file not running? If latter, how could I fix this issue?

How do you try to run your JS file?
It should be included into an html file which would then be opened inside a browser.
Sorry if you already know this but this error seems like it’s coming from Wndows itself which shouldn’t happen.

Regarding your code, game.state.add seems to be a function from Phaser 2 and you posted this message in the Phaser 3 forums. Did you use an old tutorial? Or did you post in the wrong section?

I am using the Phaser 3.15.1 version, but I used a tutorial form 2017.

So I should just run the phaser.js as a separate file in a browser to check if it works? I tried running it by double clicking the file, then clicking open, then the error showed up.

There does not seem to be a state inside Phaser.Game from what I can find in the official documentation.
Phaser 3 was released in early 2018 so I think your tutorial is a bit outdated.
If you want reliable information, I’d suggest you take a look at the labs which feature lots and lots of examples about most of the features of Phaser. You can even edit the code to play with things a bit.

Regarding the way to run your code, you should take a look at HTML and include your JS script inside.

What background do you have in computer science/programming? Do you come from another language/technology or are you beginning in this world?

Ok, so what can use as an alternative to state, in Phaser 3.15.1.

I thought that I was including my JavaScript script inside the HTML, here is the code to what I am referring to:

<!DOCTYPE>
<html lang="en">
<head>
<meta>charset="UTF-8">
<title>Nightly Neighbours Using Phaser</title>
<script type="text/javascript" src = "js/phaser.js"><script>
<script type="text/javascript" src = "js/phaser-arcade-physics.js”><script>
<script type="text/javascript" src = "js/Boot.js”><script>
<script type="text/javascript" src = "js/Preload.js”><script>
<script type="text/javascript" src = "js/NightlyNeighbours1WithPhaser.js”><script>

<script type=“text/javascript”>
  (function() {
game = new Phaser.Game(window.innerWidth  *window.devicePixelRatio, 
window.innerHeight* window.devicePixelRatio, Phaser.AUTO);
game.state.add(“Boot”, Boot);
game.state.add(“Preload”, Preload);
game.state.add(“NightlyNeighbours1WithPhaser”, Main);
game.state.start(“Boot”);
})();

With regards to my background in computer science, I am new with Phaser, but I am a computer science student, learning web game development as a hobby, with little experience with JS and HTML
Reply

Allow me to suggest this tutorial which uses Phaser 3. It will show you how to properly handle the scenes along with code demo and everything.

Moreover, this playground seems like a good starting point to play with things a bit. You will be able to try things without having to setup everything by yourself. This setup part can be a bit overwhelming, in my opinion.
The site also has several phaser sandboxes that you can easily try.

Is the file you showed the whole thing? This is indeed an HTML file but it seems to be missing the bottom part. Maybe you forgot to paste it. This file should be named something like phased-demo.html (the name is up to you but the .html extension is important. Your first post suggested that it was a .js file)
You should open the HTML file with a browser.

I could be totally off here, but I think that Windows error pops up when you double click on a javascript file from your desktop. Phaser is a javascript library that is intended to be run as part of an HTML page. Following the tutorial that Telokis linked to should help a bunch.

Thanks, a lot for the tutorial, it was insightful and helpful, also, yes I did double click on the js file, but I also tried to open the file in WebStorm afterwards - it did not open.