How can I import a TypeScript/JavaScript linrary into my server?

I want to know if there is how to import a file or a lib to use on nakama-server ?

import variavel from ‘./src/exemplo’

const exampleRpc: nkruntime.RpcFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {‘ExampleRpc called by user ID %q’, ctx.userId);

const board1 = variavel

return JSON.stringify({ success: true, board1 });


in the main.ts file it is not finding the RPC

all files are registered in the tsconfig.json

if possible an example thank you.

@juniorbraz93 Hi! You can find a fully functional TypeScript example in the Nakama project template repo. It includes Lua and Go runtime examples but you can safely ignore those. :+1:

Yes, I found it but I really want to know about the TypeScript natural import that is giving error is not working at all with the nakama server template with the RPCs

Example below of RPC file:

Import ‘nameClass’ from ‘./nameClass.ts’

function TestRpc(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {“TestRPC called!”);
return JSON.stringify({ success: true, nameClass });

and whoever I initialize in main returns this error: ( Cannot locate the name ‘TestRpc’. Did you mean ‘testRpc’? )

Example below the main file

// Copyright 2020 The Nakama Authors
// Licensed under the Apache License, Version 2.0 (the “License”);
const testRpc = ‘testRpc_js’;

function InitModule(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, initializer: nkruntime.Initializer)

initializer.registerRpc(testRpc, TestRpc); -> here and the error( Cannot find the name 'TestRpc'. Did you mean 'testRpc'? main.ts(6, 7): 'testRpc' is declared here. )

initializer.registerMatch(matchIdentifyer, {


I just want to know why when I import a file into an RPC it is invalidating the RPC?

1 Like

I’m running into the same issue: trying to use typescript’s import and Nakama can’t find InitModules anymore. Did you find a solution?

@juniorbraz93 @adbourdages If you wish to use import statements please look at configuring your TypeScript server using RollUp as documented here: TypeScript Setup - Heroic Labs Documentation