geckosio / phaser-on-nodejs

Allows you to run Phaser 3 game (including Phaser's physics engines) on Node.js
MIT License
103 stars 11 forks source link

fakeXMLHttpRequest seems to conflict with Socket.IO #6

Closed gpeles closed 3 years ago

gpeles commented 4 years ago

When a client disconnects, fs.readFile is called with the following url: node_modules/@geckosio/phaser-on-nodejs/lib/internal/process/task_queues.js Then a 'no such file or directory' error is thrown.

yandeu commented 3 years ago

I do not think this is the case. FakeXMLHttpRequest mocks the browser Web API XMLHttpRequest on node.js. I do not think that Socket.io on node.js requires this API.

Have you imported the @geckosio/phaser-on-nodejs on the client side? Make sure you only require @geckosio/phaser-on-nodejs on the server side. Can you please verify this?

gpeles commented 3 years ago

I only imported it on the server side

yandeu commented 3 years ago

Can you please share your game?

gpeles commented 3 years ago

OK I figured it out. The conflict was actually with the Source Map Support module. From their documentation:

The module will by default assume a browser environment if XMLHttpRequest and window are defined. If either of these do not exist it will instead assume a node environment. In some rare cases, e.g. when running a browser emulation and where both variables are also set, you can explictly specify the environment to be either 'browser' or 'node'.

require('source-map-support').install({
  environment: 'node'
});

So replacing import 'source-map-support/register' with the above code solves this. Closing this issue now.