Collecting page data ...ReferenceError: Cannot access 'u' before initialization #81524
Replies: 3 comments
-
I wasn't sure if I should create this discussion here or in the MikroORM repository because this problem involves both NextJS and MikroORM, so I've decided to create a discussion here and bring attention to that discussion from mikro-orm/mikro-orm#6745. If you want to help please provide your answer here to keep things centralized. |
Beta Was this translation helpful? Give feedback.
-
My first impression is Like, I imagine your Also, if you wanna know exactly where the error is I think you can turn off server minification, |
Beta Was this translation helpful? Give feedback.
-
I know I can fix this problem using index.ts, but now I have another problem. When I build with
I can fix it by putting all entities directly in index.ts instead of using it to reexport the entities from their corresponding files: index.ts // export { EntityA } from "./EntityA";
// export { EntityB } from "./EntityB";
import {
Collection,
Entity,
ManyToOne,
OneToMany,
PrimaryKey,
} from "@mikro-orm/core";
@Entity({ tableName: "a" })
export class EntityA {
@PrimaryKey()
id!: number;
@OneToMany(() => EntityB, (b) => b.a)
bs = new Collection<EntityB>(this);
}
@Entity({ tableName: "b" })
export class EntityB {
@PrimaryKey()
id!: number;
@ManyToOne(() => EntityA)
a!: EntityA;
} But why the fuck is this happening now? This problem seems more mikro-orm related than nextjs, so I'll post this question in their repo: mikro-orm/mikro-orm#6748 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Create a new NextJS app with these choices:
Install MikroORM
Delete src/app/page.tsx and src/app/layout.tsx and create these files:
src/entities/EntityA.ts
src/entities/EntityB.ts
src/entities/index.ts
src/app/route.ts
If at this point you run
npm run build
everything works wonderfully.Now let's do something funny. Let's change the imports of the entities to reference them directly instead of through index.ts:
src/entities/EntityA.ts
src/entities/EntityB.ts
Now, believe it or not, for some reason that is beyond me, this just doesn't build. If you run
npm run build
now you'll get this error:I've spent 2 whole days trying to replicate this error with as little code as possible to understand what is going on and this is the smallest amount of code I've managed to replicate this problem with.
I know I can fix it by changing the imports but I want to know:
IF IMPORTING DIRECTLY OR THROUGH INDEX.TS IS THE SAME, WHY DOES THIS HAPPEN?
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions