Trying to use Nakama on Cocos creator

Hello,
Trying to figure out how to use Nakama with cocos creator 3.3. I’m following the guide: JavaScript - Heroic Labs Documentation. When I preview in cocos, this error comes up.

 [preview-error]unhandledrejection: (intermediate value)(intermediate value)(intermediate value) is not a constructor
  [preview-error]TypeError: (intermediate value)(intermediate value)(intermediate value) is not a constructor
at _callee$ (http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:70:30)
at tryCatch (http://localhost:7456/scripting/polyfills/bundle.js:12585:20)
at Generator.invoke [as _invoke] (http://localhost:7456/scripting/polyfills/bundle.js:12804:25)
at Generator.prototype.<computed> [as next] (http://localhost:7456/scripting/polyfills/bundle.js:12638:24)
at asyncGeneratorStep (http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:6:105)
at _next (http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:8:196)
at http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:8:366
at new Promise (<anonymous>)
at HelloWorld.<anonymous> (http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:8:99)
at HelloWorld.connect (http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/HelloWorld.js:86:29)
  1. Versions: windows, nakama-js v2.3.0

This is the only component I have attached in the scene.

import { Client,Session,Socket } from '@heroiclabs/nakama-js';

@ccclass('HelloWorld')
export class HelloWorld extends Component {
start(){
this.connect();
}

async connect () {
        const client:Client = new Client("defaultkey");
}
}

Hey @RowdyWabbid we have a version of the js client that is specifically for Cocos:

Could you try this and let me know how it goes?

1 Like

It picked it up in vscode but in the editor it errored out.

@RowdyWabbid What do you mean “you picked it up in vscode” and what error did you see?

I imported the cocos client into my typescript test.ts
import { Client } from './nakama-js.umd.js'
and made a new client in the start function but when I play in cocos. It does not recognise the constructor.

I also tried turning it into a plugin from that other thread I found Nakama Js Client With Cocos Creator 3.0 - #2 by MrZak-dev

Try This instead

1 Like

sweet looks like it’s working. It did show on the Nakama Console

Happy that it works for you :slight_smile: