colyseus.js: server error: registeredHandler.klass is not a constructor

8 Jun 2018, 08:41

Hi there ! I finally succeed at running my server and my client with webpack and typescript ... but now i have a wierd error in chrome :

colyseus.js: server error: registeredHandler.klass is not a constructor

Does any one know what is it and where is it from...

I googled it and i found NOTHING it's scare me a lot ...

8 Jun 2018, 14:26

Hi @erochongit,

Make sure to use "target":"es2015" in the tsconfig.json on your server:

{
    "compilerOptions": {
        "target": "es2015",
    }
    // ...
}
8 Jun 2018, 14:40

@endel i did this it's not correct ?

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": false,
    "sourceMap": true,
    "outDir": "build"
  },
  "exclude": [
    "node_modules",
    "**/*.spec.ts",
    "**/*.test.ts"
  ],
  "include": [
    "src/**/*.ts"
  ]
}

EDIT : I have the same error when i add "target": "es2015", to my tsconfig.json.

14 Jun 2018, 15:51

same error here, any solution ?

14 Jun 2018, 16:43

@Diederik-Van-Remoortere @erochOnGit

Please see this thread https://discuss.colyseus.io/topic/57/room-error-solved/3

14 Jun 2018, 16:46

If that doesn't solve the issue, it would be nice if you could provide an example of how to reproduce the issue. Cheers!

20 Jun 2018, 12:11

Sorry for the late reply!

I just finished a project where i'm able to run client but having .klass issue ...

please use develop branch

here it is :
https://github.com/erochOnGit/nodeGame

If you are not able to run it properly tell me i'll help you

21 Jun 2018, 02:11

Hi @erochOnGit, I see. Thanks for sharing your project.

The issue you're having is because you're using both commonjs and es6 module systems at the same time. A common practice is to either always use require + module.exports, or import + export, never both.

You can fix the issue by using import { MyRoom } from "./defaultRoom.ts" here. Or by exporting the room using commonjs, by using module.exports = class MyRoom {...

@Diederik-Van-Remoortere is that your scenario as well?

21 Jun 2018, 14:32

Hi all,

I'm just starting out with your framework and I'm rather new to ES6 as well, so I'm probably a bit confused.

The things I'm confused about are:

  • should I use babel ? if yes, which version ? @erochOnGit in your nodeGame repo you are using @babel which seems to be a beta version of babel, is this intentionally ?
  • which babel preset should I use ?
  • should I use type script or javascript ? (i prefer the later...)
  • I 'd prefer to write my code using the ES6 syntax (i.e. using import i.s.o require()...), your examples are also written in it...

It might be a good idea to update your getting started section on the website as it is currently a bit weird to clone a git repo to start a new project instead of using npm install commands.... I'm just being frank here ;)

I stumbled upon your project by accident for a multiplayer demo game I'm currently co-working on with some colleagues, and it would be nice to continue using Colyseus for it...

Thanks for your responses, apologies for the late reply.

Best Regards,
Diederik

22 Jun 2018, 15:50

@diederik-van-remoortere

You must use typescript, I tried with babel but it was wrong.
In my repo I forgot to remove babel from the package.json

22 Jun 2018, 15:53

@endel said in colyseus.js: server error: registeredHandler.klass is not a constructor:

Or by exporting the room usin

I'll try it the week end and come back to you later.
Thx for the help so far.