fixing warnings when bundling Colyseus server with webpack

The game server I am currently creating is written in TypeScript and includes the Colyseus server as a node module. Everything is compiled and bundled with webpack because I think that deployment of a game server gets a lot easier by simply copying one bundled file.

When using webpack to compile and bundle the Colyseus server (yes, the Colyseus server, not the Colyseus client) there are several warnings, at least in my combination of versions of node, webpack, TypeScript and Colyseus. I took the following steps to fix those warnings. In the future somebody might search for those warnings, might find this post and might consider it helpful.

node 12.19.0
webpack 4.44.2
TypeScript 4.0.5
Colyseus 0.14.0

I added the following to my webpack.config.js file:

plugins: [
  // problem: bundling Colyseus with webpack causes warnings regarding hiredis
  // solution: force webpack to ignore hiredis
  // source: https://github.com/NodeRedis/node-redis/issues/790#issuecomment-501869990
  new webpack.IgnorePlugin(/^hiredis$/),
  // problem: bundling Colyseus with webpack causes warnings regarding unexpected characters in default-gateway module
  // reason: default-gateway/index.js contains a dynamic require command and webpack tries to read readme and license files
  // solution: force webpack to ignore readme and license files
  new webpack.IgnorePlugin(/README.md$/),
  new webpack.IgnorePlugin(/LICENSE$/)
]
// problem: bundling Colyseus with webpack causes warnings regarding optional dependencies bufferutil and utf-8-validate
// solution: npm install --save-optional bufferutil utf-8-validate
// source: https://github.com/websockets/ws/issues/1220#issuecomment-717785572

The module mentioned in the last hint must be installed manually.

Here are the original warnings, hopefully to be found with search engines:

WARNING in ./node_modules/colyseus/node_modules/ws/lib/buffer-util.js
Module not found: Error: Can't resolve 'bufferutil' in 'C:\CUSTOMFOLDER\node_modules\colyseus\node_modules\ws\lib'
 @ ./node_modules/colyseus/node_modules/ws/lib/buffer-util.js
 @ ./node_modules/colyseus/node_modules/ws/lib/websocket.js
 @ ./node_modules/colyseus/node_modules/ws/index.js
 @ ./node_modules/colyseus/lib/Server.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./CUSTOMFILE.ts

WARNING in ./node_modules/colyseus/node_modules/ws/lib/validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in 'C:\CUSTOMFOLDER\node_modules\colyseus\node_modules\ws\lib'
 @ ./node_modules/colyseus/node_modules/ws/lib/validation.js
 @ ./node_modules/colyseus/node_modules/ws/lib/receiver.js
 @ ./node_modules/colyseus/node_modules/ws/index.js
 @ ./node_modules/colyseus/lib/Server.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./CUSTOMFILE.ts

WARNING in ./node_modules/default-gateway/README.md 1:0
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> # default-gateway
| [![](https://img.shields.io/npm/v/default-gateway.svg?style=flat)](https://www.npmjs.org/package/default-gateway) [![](https://img.shields.io/npm/dm/default-gateway.svg)](https://www.npmjs.org/package/default-gateway) [![](https://api.travis-ci.org/silverwind/default-gateway.svg?style=flat)](https://travis-ci.org/silverwind/default-gateway)
| 
 @ ./node_modules/default-gateway sync ^\.\/.*$ ./README.md
 @ ./node_modules/default-gateway/index.js
 @ ./node_modules/internal-ip/index.js
 @ ./node_modules/colyseus/lib/discovery/index.js
 @ ./node_modules/colyseus/lib/Server.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./CUSTOMFILE.ts

WARNING in ./node_modules/default-gateway/LICENSE 1:14
Module parse failed: Unexpected token (1:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> Copyright (c) silverwind
| All rights reserved.
| 
 @ ./node_modules/default-gateway sync ^\.\/.*$ ./LICENSE
 @ ./node_modules/default-gateway/index.js
 @ ./node_modules/internal-ip/index.js
 @ ./node_modules/colyseus/lib/discovery/index.js
 @ ./node_modules/colyseus/lib/Server.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./CUSTOMFILE.ts

ERROR in ./node_modules/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in 'C:\CUSTOMFOLDER\node_modules\redis-parser\lib'
 @ ./node_modules/redis-parser/lib/hiredis.js 3:14-32
 @ ./node_modules/redis-parser/lib/parser.js
 @ ./node_modules/redis-parser/index.js
 @ ./node_modules/redis/index.js
 @ ./node_modules/colyseus/lib/presence/RedisPresence.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./CUSTOMFILE.ts

Hi @TeeTeeHaa, welcome! 👋

I'm not familiar with compiling server-side code with Webpack, I usually only use plain TypeScript for server-side code. Do you mind sharing a sample repository with your webpack setup so I can have a look at it?

Cheers!

Hello @endel , thank you for your time.
I do not expect you to fix this because I assume this cannot be fixed by Colyseus itself.
Nevertheless here is a minimal code example which causes those warnings (without my fixes suggested above):
https://gist.github.com/TeeTeeHaa/5e38ccf475a9efc54c958650020d61cc