# matchCreate error

**URL:** <https://forum.heroiclabs.com/t/matchcreate-error/4100>\
**Category:** Runtime Framework\
**Tags:** server-framework, typescript\
**Created:** [July 20, 2023, 3:09am UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100 "2023-07-20T03:09:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/justin/32/1702_2.png) [@justin](https://forum.heroiclabs.com/u/justin)\
**Post date:** [July 20, 2023, 3:09am UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100/1 "2023-07-20T03:09:20Z")

</div>

I have this code from docs:

```auto
function findOrCreateMatch(ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {
  logger.info('findOrCreateMatch rpc called');
  const limit = 10;
  const isAuthoritative = true;
  const minSize = 1;
  const maxSize = 2;
  const label = "";
  var matches = nk.matchList(limit, isAuthoritative, label, minSize, maxSize, "");

  // If matches exist, sort by match size and return the largest.
  if (matches.length > 0) {
    matches.sort(function (a, b) {
      return a.size >= b.size ? 1 : -1;
    });
    return matches[0].matchId;
  }

  // If no matches exist, create a new one using the "lobby" module and return it's ID.
  var matchId = nk.matchCreate('supermatch', { debug: true });
  return JSON.stringify({ matchId });
}

```

however when I send request in API EXPLORER it gives me an error:  
`rpc error: code = Internal desc = GoError: error creating match: error creating match: not found at github.com/heroiclabs/nakama/v3/server.(*runtimeJavascriptNakamaModule).matchCreate.func1 (native)`

what am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![mofirouz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/mofirouz/32/1523_2.png) [@mofirouz](https://forum.heroiclabs.com/u/mofirouz)\
**Post date:** [July 20, 2023, 10:00am UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100/2 "2023-07-20T10:00:39Z")

</div>

Can you show us how you register/define “supermatch” ?

---

<div class="post-metadata">

**Author:** ![justin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/justin/32/1702_2.png) [@justin](https://forum.heroiclabs.com/u/justin)\
**Post date:** [July 20, 2023, 10:08am UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100/3 "2023-07-20T10:08:28Z")

</div>

been reading more about the docs, and found out that it might be the problem, I haven’t registered/defined it on my `InitModule` . Heres my `main.ts` that has the `InitModule`:

```auto
function InitModule(context: nkruntime.Context, logger: nkruntime.Logger, nakama: nkruntime.Nakama, initializer: nkruntime.Initializer) {
  initializer.registerRpc('matchmaker', findOrCreateMatch)
  logger.info('Javascript module loaded')
}

```

although I have tried this but it still doesn’t work:  
`nk.matchCreate('data/modules/build/index.js', { });`

I’m confused on how do I register/define the module, can you point me to the right direction? really appreciate it.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [July 20, 2023, 12:47pm UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100/4 "2023-07-20T12:47:02Z")

</div>

@justin you have to register the match handlers as well (see this example: [https://github.com/heroiclabs/nakama-project-template/blob/master/main.ts#L23](https://github.com/heroiclabs/nakama-project-template/blob/master/main.ts#L23)), and then you call `matchCreate` specifying the name you set upon registration.

I suggest you have a good look at the whole project I linked as it implements a tic-tac-toe backend in TS (and Go) for Nakama.

Best

---

<div class="post-metadata">

**Author:** ![justin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/justin/32/1702_2.png) [@justin](https://forum.heroiclabs.com/u/justin)\
**Post date:** [July 20, 2023, 12:51pm UTC](https://forum.heroiclabs.com/t/matchcreate-error/4100/5 "2023-07-20T12:51:30Z")

</div>

I see, so that’s what’s lacking in there. Thanks a bunch!
