Phaser3 - Navigator is Not Defined

Hello!

I have seen two related posted to this topic, but I cannot find any further information so I am resorting to a forum post.

I am using Node.js and Express.js as the server host. I am using npm to install phaser.

No matter what I do, I get “navigator is not defined” in reference to the following module code

node_modules\phaser\src\device\OS.js:69
var ua = navigator.userAgent;

I am fairly experienced with Express.js in general, and everything seems to be running fine. The issue appears to be with Phaser. I’m not sure what the problem is. I have seen individuals saying that Phaser 3 is not meant to be loaded in the server, yet all of the Getting Started documentation suggests this is a requirement, so I don’t understand. I have looked through multiple third-party guides as well, but to no avail.

:wave:

You probably don’t need to run Phaser on the server. You just need to run a web server of some kind so Phaser works properly in the browser.

Sorry for my confusion here, but Express is the web server in this context, so I guess I’m not sure what I’m supposed to be using.

Express is fine :slight_smile: , just don’t include Phaser in any of your Express/Node code. I’m assuming the “navigator is not defined” error is coming from Node.

Thank you for trying to help me. I’m probably being an idiot here, but are you saying that I need to serve the index.html from a separate webserver and not within the code that the game.js file is running in? Seems weird to me. Maybe there’s something I’m fundamentally misunderstanding about Phaser.

If you have a project setup like Getting Started with Phaser 3 and Node.js then

  • server.js has the Node/Express code only
  • game.js has new Phaser.Game() etc.
  • index.html includes phaser.js and game.js

You start the server and then open index.html in the browser.