Importing Schemas from other module doesn't work.
See original GitHub issueIssue Description
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 {
@type("number")
whatever = 2;
}
When a client joins the server, i get the error on the client:
JOIN ERROR { Error: SchemaSerializer error. See: https://docs.colyseus.io/migrating/0.10/#new-default-serializer
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 Object.next (/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: https://docs.colyseus.io/migrating/0.10/#new-default-serializer
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 Generator.next (<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:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
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?