While trying to run my Next.js application in typescript, I encountered the following error:
Error - ReferenceError: Cannot access 'Member' before initialization
After consulting the documentation at https://mikro-orm.io/docs/relationships#relations-in-esm-project, it seems that the suggested solution does not resolve the issue. When attempting to import Rel like this:
import { Rel } from '@mikro-orm/core';
and applying it around the entity Member, a new error occurs:
A type referenced in a decorated signature must be imported with 'import type' or a namespace import when 'isolatedModules' and 'emitDecoratorMetadata' are enabled.
Even after setting these options to false, the problem persists and more errors surface.
The problematic entity contains the following code:
import { Entity, PrimaryKey, Property, ManyToOne, Rel} from "@mikro-orm/core";
import { Member } from "./Member";
@Entity()
export class File{
@PrimaryKey({name: "fileId"})
id!: number;
@Property()
name!: string;
@Property()
type!: string;
@Property({ type: "longblob"})
data!: Buffer;
@Property()
size!: number;
@Property({name: "createdAt", type: "datetime", defaultRaw: "CURRENT_TIMESTAMP"})
createdAt!: Date;
@ManyToOne({entity: () => Member})
member!: Rel<Member>;
@Property({name: "inschrijvingsdocument"})
isSignupDoc!: boolean;
@Property({name: "opleidingsdocument"})
isOpleidingsDoc!: boolean;
}
If anyone has a solution to this issue, your help would be greatly appreciated.