Skip to content

Instantly share code, notes, and snippets.

@TeeTeeHaa

TeeTeeHaa/main.ts

Created Dec 7, 2020
Embed
What would you like to do?
minimal code example to show warnings when building Colyseus server with webpack

reference

https://discuss.colyseus.io/topic/424/fixing-warnings-when-bundling-colyseus-server-with-webpack

files

  • readme.md
  • package.json
  • tsconfig.json
  • webpack.config.js
  • webpack.bat (for Windows)
  • main.ts

instructions

  1. npm install
  2. npm run build

output


> demo@1.0.0 build C:\demo
> webpack --config webpack.config.js

Hash: 5a6cc71b15fda019b94a
Version: webpack 4.44.2
Time: 5110ms
Built at: 2020-12-07 20:54:53
            Asset      Size  Chunks                   Chunk Names
    main-built.js  1000 KiB       0  [emitted]        main
main-built.js.map   1.1 MiB       0  [emitted] [dev]  main
Entrypoint main = main-built.js main-built.js.map
  [0] ./main.ts 282 bytes {0} [built] [1 error]
  [7] external "http" 42 bytes {0} [built]
  [8] external "net" 42 bytes {0} [built]
 [11] external "events" 42 bytes {0} [built]
 [12] external "https" 42 bytes {0} [built]
 [13] external "tls" 42 bytes {0} [built]
 [14] external "crypto" 42 bytes {0} [built]
 [15] external "url" 42 bytes {0} [built]
 [17] external "zlib" 42 bytes {0} [built]
 [22] external "stream" 42 bytes {0} [built]
 [35] external "tty" 42 bytes {0} [built]
 [36] external "util" 42 bytes {0} [built]
 [38] external "os" 42 bytes {0} [built]
[122] external "assert" 42 bytes {0} [built]
[139] external "querystring" 42 bytes {0} [built]
    + 150 hidden modules

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

WARNING in ./node_modules/ws/lib/validation.js
Module not found: Error: Can't resolve 'utf-8-validate' in 'C:\demo\node_modules\ws\lib'
 @ ./node_modules/ws/lib/validation.js
 @ ./node_modules/ws/lib/receiver.js
 @ ./node_modules/ws/index.js
 @ ./node_modules/colyseus/lib/Server.js
 @ ./node_modules/colyseus/lib/index.js
 @ ./main.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
 @ ./main.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
 @ ./main.ts

ERROR in ./node_modules/redis-parser/lib/hiredis.js
Module not found: Error: Can't resolve 'hiredis' in 'C:\demo\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
 @ ./main.ts
/// <reference types="node" />
import { Server } from "colyseus";
const port = 3000;
const gameServer = new Server();
gameServer.listen(port);
{
"name": "demo",
"version": "1.0.0",
"description": "https://discuss.colyseus.io/topic/424/fixing-warnings-when-bundling-colyseus-server-with-webpack",
"main": "javascript-built-by-webpack/main.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"watch": "webpack --config webpack.config.js --watch"
},
"author": "TeeTeeHaa",
"license": "WTFPL",
"devDependencies": {
"@types/node": "12.19.0",
"ts-loader": "^8.0.11",
"tslint": "^6.1.3",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
},
"dependencies": {
"colyseus": "^0.14.2"
}
}
// https://www.typescriptlang.org/tsconfig
{
/* === Compiler Options === */
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"resolveJsonModule": true, /* Allow import of JSON modules, see https://mariusschulz.com/blog/importing-json-modules-in-typescript */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "javascript-built-by-tsc/", /* Redirect output structure to the directory. */
// "rootDir": "", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [ /* List of folders to include type definitions from. */
"node_modules/@types"
],
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Command Line */
"preserveWatchOutput": true, /* Whether to keep outdated console output in watch mode instead of clearing the screen every time a change happened. */
/* Advanced Options */
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
// "listFiles": true /* Print names of files part of the compilation. */
// "extendedDiagnostics": true /* You can use this flag to discover where TypeScript is spending it’s time when compiling. */
}
}
@node node_modules\webpack\bin\webpack.js %*
// https://webpack.js.org/configuration/
const path = require('path')
module.exports = {
target: 'node',
mode: 'none',
entry: {
main: './main.ts' // requires './'
},
output: {
path: path.join(__dirname, '/javascript-built-by-webpack/'), // path.join, not path.resolve!
filename: '[name]-built.js'
},
module: {
rules: [
{
exclude: '/node_modules/',
use: [
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.json'
}
}
],
test: /\.tsx?$/
}
]
},
resolve: {
extensions: ['.js', '.json', '.jsx', '.css', '.ts', '.tsx']
},
devtool: 'source-map'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment