Solution: The rollup.config.mjs
provided in the documentation is not correct or outdated.
Searching the forum, I came across this message:
If you do not plan on updating this documentation, then please add a disclaimer at the top, and save people the pain of unknowingly getting stuck trying to get an outdated tutorial to work.
If I replace the rollup.config.mjs
contents provided by the tutorial with the version found in the GitHub repo:
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import babel from "@rollup/plugin-babel";
import typescript from "@rollup/plugin-typescript";
const extensions = [".mjs", ".js", ".ts", ".json"];
export default {
input: "./src/main.ts",
external: ["nakama-runtime"],
plugins: [
// Compile TS to check types
typescript(),
// Allows node_modules resolution
resolve(),
json(),
// Resolve CommonJS modules
commonjs(),
// Compile TS and build to ES5
babel({
extensions: extensions,
babelHelpers: "bundled",
}),
],
output: {
format: "cjs",
file: "build/index.js",
},
};
The built JavaScript is now correct and Nakama starts up correctly:
'use strict';
function InitModule(ctx, logger, nk, initializer) {
logger.info("TypeScript module loaded.");
}
!InitModule && InitModule.bind(null);