Uncaught Error: ChangeTree: missing index for field "undefined"

Hello everyone,

I'm currently building a web game (based on colyseus and VueJS).

I had no problem at all during the whole development, but today I just saw this error pop in the console at a specific moment.
It does not block the code and execution.
It is due to this line of code, server-side, in a listener for client request

this.state.players.get(client.sessionId).jokers.get(packet.datas).available = false;

I have tried to write it that way but the error is still here

let player = this.state.players.get(client.sessionId);
let joker = player.jokers.get(packet.datas);
joker.available = false;

the property jokers is a mapSchema binded with jokers "slug" so it's easy to find them.

Why is it causing an error and do you have a tip to avoid it ?

Thanks !

Hi Maël, welcome! 👋

Are you using @filter() or @filterChildren()?

Can you please share your source-code with us, so we can have a bigger picture of the operations on MapSchema? I'm curious to see what's going on as I've never seen this error before!

Feel free to ping me on Discord (endel#2163) or email (endel[at]lucidsight.com)


Hi @endel ! Thanks

thank for answering, I'm not using @filter() or @filterChildren().

Here is the code of the MapSchema :

export class Joker extends Schema {
    type: string;

    slug: string;

    name: string;

    available: boolean = true;

    isUsed: boolean = false;

and it's inplementation in the Schema for the Player

@type({ map: Joker })
jokers: MapSchema<Joker>;

I initialize it here (maybe here is the bad code haha) :

let jokers = new MapSchema<Joker>();
    this.jokers.forEach((jk) => {
        let joker = new Joker({
        type: jk.type,
        slug: jk.slug,
        name: jk.name,
        available: true,
        isUsed: false
    jokers.set(jk.slug, joker);

the jokers array

jokers = [
        { type: 'bonus', slug: "cdp", name: "Coup d'pouce" },
        { type: 'attaque', slug: "pjn", name: "Petit jaune" },

And the error throws when I do this :
this.state.players.get(client.sessionId).jokers.get(packet.datas).available = false;

Just to know, I use this.state.players.get(client.sessionId).jokers.get(packet.datas).available in a if right before and it doesn't throw error.
Plus, the error is throwing on client-side in colyseus.js and nothing shows up on server-side.

Hope it will help !


Hello 👋 @atzmael did you have any luck figuring this out? I, too, currently get this error every once in a while but only client-side 🤔

I get this stacktrace btw.:

Uncaught Error: ChangeTree: missing index for field "undefined"
    at e.assertValidIndex (index.js:388)
    at e.touch (index.js:268)
    at e.touchParents (index.js:278)
    at e.change (index.js:264)
    at e.set [as x] (index.js:1308)
    at e.decode (index.js:2570)
    at t.patch (NoneSerializer.ts:7)
    at e.patch (Room.ts:267)
    at e.onMessageCallback (Room.ts:252)