Importing NakamaJs module


My Code:

var ItsAscript = pc.createScript('itsAscript');

ItsAscript.prototype.initialize = function() {
    var nakamajs = document.createElement('script');
    nakamajs.src = '/nakama-js.umd.js';

    var client = new nakamajs.Client("defaultkey", "", 7350);
    client.ssl = false;
    print("print ho rha hai");
    var email = "";
    var password = "batsignal";
    var session = client.authenticateEmail({ email: email, password: password });;

// update code called every frame
ItsAscript.prototype.update = function(dt) {

//const client = new nakamajs.Client("defaultkey");

I’m trying to import NakamaJs module but I keep getting this error:

[ItsAScript.js?id=16996646&branchId=5a76c294-f453-41ae-be63-d7b54f2861dd:15]: nakamajs.Client is not a constructor

TypeError: nakamajs.Client is not a constructor


I’m also trying to use Nakama with PlayCanvas, if anyone has any suggestions that would be welcome.

I’ve just put nakama-js.umd.js in the scripts folder, and then in my other .js script in the initialize() function, I use OP’s code to import Nakama (just the 3 lines of code in his post), but the Chrome debug log shows:
Failed to load resource: the server responded with a status of 404 (Not Found)

EDIT: Nakama’s documentaion ( explains that the only requirement is to include nakama-js.umd.js in the script html tag. So I’m about to search the forums for how to do that.


If you have nakama-js.umd.js in the project, then it’s automatically added to the header. Just make sure that it is first in the script loading order in the project settings.


Thank you @yaustar. This has worked for me.