Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing Schemas from other module doesn't work.

See original GitHub issue

My setup: -typescript server and typescript client as 2 different projects, importing a common third project that contains shared/common stuff, especially the data model and the Schema, and exposes them as es6 modules

Even with a simple Schema such as:

export class TestSchema extends Schema {
    whatever = 2;

When a client joins the server, i get the error on the client:

JOIN ERROR { Error: SchemaSerializer error. See:
    at new MatchMakeError (/home/stefano/project-x/project-x-webclient/node_modules/colyseus.js/lib/Client.js:58:28)
    at Client.<anonymous> (/home/stefano/project-x/project-x-webclient/node_modules/colyseus.js/lib/Client.js:182:35)
    at step (/home/stefano/project-x/project-x-webclient/node_modules/colyseus.js/lib/Client.js:45:23)
    at (/home/stefano/project-x/project-x-webclient/node_modules/colyseus.js/lib/Client.js:26:53)
    at fulfilled (/home/stefano/project-x/project-x-webclient/node_modules/colyseus.js/lib/Client.js:17:58)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7) code: 4213 }

and on the server:

Error: SchemaSerializer error. See:
    at SchemaSerializer.reset (/home/stefano/project-x/project-x-server/node_modules/colyseus/lib/serializer/SchemaSerializer.js:13:19)
    at GameRoom.setState (/home/stefano/project-x/project-x-server/node_modules/colyseus/lib/Room.js:108:26)
    at GameRoom.onCreate (/home/stefano/project-x/project-x-server/src/GameRoom.ts:12:14)
    at /home/stefano/project-x/project-x-server/node_modules/colyseus/lib/MatchMaker.js:214:28
    at (<anonymous>)
    at /home/stefano/project-x/project-x-server/node_modules/colyseus/lib/MatchMaker.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/home/stefano/project-x/project-x-server/node_modules/colyseus/lib/MatchMaker.js:3:12)
    at createRoom (/home/stefano/project-x/project-x-server/node_modules/colyseus/lib/MatchMaker.js:200:12)
    at Object.<anonymous> (/home/stefano/project-x/project-x-server/node_modules/colyseus/lib/MatchMaker.js:44:30)

If the TestSchema class is defined in the server project, no error is encountered, it only triggers when I import it from the common project. The error fails on a instanceof check, I guess because the server and the common project have 2 different versions of the Schema class and therefore that check fails.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

MastroLinduscommented, Jan 10, 2020

New version fixed it. I guess that using some js bundlers it should be possible to detect if the same module with the same version gets imported twice and ensure that only one copy is bundled, and that also should fix this issue. However the newer code also works, thanks!, Feel free to close the issue or keep it around until 0.12.x is stable!

Zielakcommented, Jan 10, 2020

MastroLindus is right. I stumbled upon the same issue last week while I was messing about with npm link. In my case, my whole “base” project is a monorepo (Lerna managed), so both client and server side are in one dir, using the same “shared” node_modules. Then i have seperate project for the actual game, which is importing the “base” client and server libs. Maybe that could be your temporary solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schemas in external module not working in Node.js
Personally I created separate "common" project with an init method to register all of the models with mongodb, and call the init method...
Read more >
The specified module 'Module Name' was not loaded because ...
Problem: When trying to import the PnP PowerShell module, I got an error message “Import-Module: The specified module 'SharePointPnPPowerShellOnline' was ...
Read more >
Loading GraphQL Schemas from Different Sources
Load GraphQLSchema by Using Different Loaders from Different Sources · Using #import Expression · Binding to HTTP Server.
Read more >
ModuleNotFoundError: no module named Python Error [Fixed]
When you try to import a module in a Python file, Python tries to resolve this module in several ways. Sometimes, Python throws...
Read more >
Object schema import | Jira Service Management Data Center ...
You need to be an Assets Manager for an object schema to create, configure, and enable imports. Import fields. Once you've chosen your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found