InitModule (TypeScript) executed twice when start nakama 3.0

I’m running sample code from here https://heroiclabs.com/docs/runtime-code-typescript-setup/ with a little modification

  • delete “module”: “CommonJS” in tsconfig
  • start nakama with: nakama --runtime.js_entrypoint “…/…/build/index.js”

When nakama starts, the code in InitModule is executed twice.

My main.ts file:

let count = 0;
let InitModule: nkruntime.InitModule =
    function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer) {
        logger.info("Hello World! " + count++);
    }

Output:

{“level”:“info”,“ts”:“2021-01-20T10:33:14.010+0700”,“caller”:“server/runtime_javascript.go:494”,“msg”:“Initialising JavaScript runtime provider”,“path”:"/Users/cuong/Documents/TDG/Cocos/nakama/data/modules",“entrypoint”:"…/…/build/index.js"}
{“level”:“info”,“ts”:“2021-01-20T10:33:14.011+0700”,“caller”:“server/runtime_javascript_logger.go:68”,“msg”:“Hello World! 0”}
{“level”:“info”,“ts”:“2021-01-20T10:33:14.011+0700”,“caller”:“server/runtime_javascript_logger.go:68”,“msg”:“Hello World! 1”}
{“level”:“info”,“ts”:“2021-01-20T10:33:14.011+0700”,“caller”:“server/runtime_javascript.go:1419”,“msg”:“JavaScript runtime modules loaded”}

So, is this a bug?

Hey @Okno, after inspection I can confirm this to be a bug, I’ve opened the following issue: JS Runtime invokes InitModule function twice · Issue #530 · heroiclabs/nakama · GitHub.

We’ll work on a fix and a new release soon to address it, thanks for your post.

1 Like