Colyseus Schema in Cocos

Is it possible to use the generated schema from Colyseus inside cocos-creator? Installing @colyseus/schema and using the generated schemas doesn’t seem to work

Cocos package.json
image

Generated Schema File

Error:

Found possible circular reference in "http://localhost:7456/scripting/x/mods/fs/0/assets/scripts/client-side/User.js", happened when use "type" imported from "@colyseus/schema"  Error: 
    execute User.ts:12
    doExec system-core.js:279
    postOrderExec system-core.js:275
    postOrderExec system-core.js:261
    postOrderExec system-core.js:259
    postOrderExec system-core.js:261
    postOrderExec system-core.js:259
    C system-core.js:232
    promise callback*topLevelLoad system-core.js:231
    import system-core.js:38
    promise callback*systemJSPrototype.import system-core.js:36
    import global.js:52
    import system-core.js:128
    <anonymous> main.js:1
    o main.js:1
    o main.js:1
    a main.js:1
    promise callback*c main.js:1
    a main.js:1
    promise callback*c main.js:1
    a main.js:1
    promise callback*c main.js:1
    n main.js:1
    n main.js:1
    <anonymous> main.js:1
    <anonymous> index.js:1
    s index.js:1
    s index.js:1
    a index.js:1
    promise callback*c index.js:1
    a index.js:1
    promise callback*c index.js:1
    a index.js:1
    promise callback*c index.js:1
    a index.js:1
    promise callback*c index.js:1
    i index.js:1
    i index.js:1
    <anonymous> index.js:1
    <anonymous> index.js:1
    s index.js:1
    s index.js:1
    i index.js:1
    i index.js:1
    <anonymous> index.js:1
    onload (index):148
    promise callback*window.onload (index):147
    EventHandlerNonNull* (index):146

It seems to be saying there is some kind of circular reference for the “type” decorator, which is preventing compilation.

Any help is appreciated!

I dont know a lot about this but I can ask engineering to have a look.

And it looks like Creator 3.3.2?

Yes, it is version 3.3.2
Thank you

It is possible to use @colyseus/schema. I have installed and working properly.


Here is my demo:
55351.zip (1.6 MB)

1 Like

When I ran npm install and opened the project in cocos, it gave me the same error

If you are on Mac, could this be a Windows specific issue? Could you also specify your node version so i know its not a node version mismatch? I am using 16 LTS

Sorry, I overlooked this error, you can open project settings and set Exports Conditions to empty,and it will works.


The second way, you can use Schema like this:

in this way,you need to add “allowSyntheticDefaultImports”: true to tsconfig.json.

2 Likes

The second way (I think specifically the import s from @colyseus/schema) made it work, now the error is not there. The other method still seemed to have that error.
Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.