Did you experience this error?
ReferenceError: Cannot access 'User' before initialization
I'm having trouble getting past this. I think it's due to the fact that I'm using relations between entities and it's creating a circular dependency with how NextJS compiles it. I've seen it referenced in a few places online, but I haven't found any solutions that have worked for me.
It's not elegant and I'm strongly considering moving away from TypeORM for this project. It worked beautifully in a different project with a persistent server, but not so elegantly in this one using static API routes that Next provides.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Did you experience this error?
ReferenceError: Cannot access 'User' before initialization
I'm having trouble getting past this. I think it's due to the fact that I'm using relations between entities and it's creating a circular dependency with how NextJS compiles it. I've seen it referenced in a few places online, but I haven't found any solutions that have worked for me.
I'm late, but I resolved this by using interfaces for typing instead of the Entities themselves.
User:
User Meta:
I hope this helps future folk!
still having the same error without no solution
If this is the error I remember, I ended up making all my relation types partials.
Hey Derek, mind posting an example of how you fixed this?
In short:
comments!: Partial<Comment[]>
. I made every relationship type to another model a Partial of it.You can see all of my models at github.com/papyrcms/papyrcms/blob/.... The example is from the Blog model, but several are like this.
It's not elegant and I'm strongly considering moving away from TypeORM for this project. It worked beautifully in a different project with a persistent server, but not so elegantly in this one using static API routes that Next provides.