Error: Object type 'Project' not found in schema

Hi,

I have encountered the error as below when trying to insert ‘Project’ into the collection.
Uncaught (in promise) Error: Object type 'Project' not found in schema.

FYI, I am working with Electron + React.

In Schemas.js(autogenerated from Realm UI)

export const ProjectSchema = {
  name: "Project",
  properties: {
    _id: "string",
    assignees: "string<>",
    endDate: "date?",
    projectName: "string",
    realmId: "string",
    startDate: "date?",
  },
  primaryKey: "_id",
};

Schema in Realm UI:

{
  "title": "Project",
  "bsonType": "object",
  "required": [
    "_id",
    "projectName",
    "realmId"
  ],
  "properties": {
    "_id": {
      "bsonType": "string"
    },
    "projectName": {
      "bsonType": "string"
    },
    "assignees": {
      "bsonType": "array",
      "uniqueItems": true,
      "items": {
        "bsonType": "string"
      }
    },
    "realmId": {
      "bsonType": "string"
    },
    "startDate": {
      "bsonType": "date"
    },
    "endDate": {
      "bsonType": "date"
    }
  }
}

Rules set in Realm UI:
image

export function createRealmConfig(user, partitionValue, schema) {
  return {
    schema: [schema], // predefined schema
    sync: {
      user: user, // already logged in user
      partitionValue: partitionValue,
    },
  };
}

Trying to create a dummy project:

const createProject = () => {
    const projectConfig = createRealmConfig(
      app.currentUser,
      publicRealmId,
      ProjectSchema
    );
    const projectId = uuid().toString();
    getRealm(projectConfig).then((realm) => {
      realm.write(() => {
        realm.create(ProjectSchema.name, {
          realmId: publicRealmId,
          projectName: "Project 1",
          _id: projectId,
        });
      });

      return () => {
        realm.close();
      };
    });
}

Permission for syncing:
image

I have tried to terminate sync, reset permissions and rules, delete local realm cache file over and over again but with no success.

Please help.

Thanks,
Vincent

The problem was due to opening the realm without all the needed schemas in one go.
Current solution is to create kind of a global realm with all the schema needed.

export async function getPublicRealmIfNotExist(currentAuthenticatedUser) {
  if (publicRealm !== null && publicRealm.isClosed !== true) {
    return publicRealm;
  }

  const credentials = Realm.Credentials.jwt(
    currentAuthenticatedUser.signInUserSession.idToken.jwtToken
  );

  await app.logIn(credentials);

  const config = {
    schema: publicSchemaList, // predefined schema
    sync: {
      user: app.currentUser, // already logged in user
      partitionValue: publicRealmId,
      error: publicRealmErrorSync,
    },
  };

  return (publicRealm = await Realm.open(config));
}

Thanks,
Vincent