ReferenceError: Cannot access 'BrandEntity before initialization
See original GitHub issueIssue type:
[X] question [X] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[X] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[X] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
When trying to read brands (BrandEntity
) I am getting the following error:
ReferenceError: Cannot access 'BrandEntity' before initializatio
import {
Entity,
PrimaryGeneratedColumn,
Column,
BaseEntity,
ManyToOne,
PrimaryColumn,
JoinColumn,
VersionColumn, OneToMany
} from "typeorm";
import {UserEntity} from "./UserEntity";
import {ResponseEntity} from "./ResponseEntity";
@Entity()
export class BrandEntity {
@PrimaryColumn()
id: string;
@Column({
length: 150
})
name: string;
@ManyToOne(type => UserEntity)
owner: UserEntity;
@OneToMany(type => ResponseEntity, (response: ResponseEntity) => response.brand, {
//cascadeInsert: true,
//cascadeUpdate: true,
//cascadeRemove: true
cascade: true
})
responses: ResponseEntity[]
}
import {Entity, PrimaryGeneratedColumn, Column, BaseEntity, ManyToOne} from "typeorm";
import {BrandEntity} from "./BrandEntity";
@Entity()
export class ResponseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column({
length: 1000,
nullable: false
})
text: string;
@Column({
nullable: false
})
emotion: 'sad' | 'neutral' | 'happy';
@ManyToOne(type => BrandEntity, brand => brand.responses, {
eager: true
})
brand: BrandEntity;
}
Relevant config:
{
"name": "development",
"type": "postgres",
"host": "localhost",
"username": "postgres",
"password": "postgres",
"database": "local",
"synchronize": true,
"logging": true,
"entities": [
"./src/server/entities/**.ts"
],
"migrations": [
"./src/server/migrations/**.ts"
],
"dropSchema": true
}
Is there something wrong with my relationship? Otherwise, I believe this is a bug. Any thoughts are greatly appreciated!
Olav
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
ReferenceError: can't access lexical declaration 'X' before ...
The JavaScript exception "can't access lexical declaration `variable' before initialization" occurs when a lexical variable was accessed ...
Read more >Cannot access 'variable_name' before initialization
When you assign variables using $: you cannot assign them as part of other variables declared using let , const , or var...
Read more >referenceerror: cannot access before initialization react
The error is telling you that the variable steps is initialized on line 7, but you're using it on line 6 to set...
Read more >Cannot access x before initialization" - Ep 10 - YouTube
JS Casts 10 - How to fix "Uncaught ReferenceError : Cannot access x before initialization " in JavaScript.
Read more >Javascript - referenceerror: cannot access <variable name ...
but not getting why it is giving error. It's giving - ReferenceError: Cannot access 'r1' before initialization. Please help me. What I have ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@m4tta I ended up ditching Typeorm and going for “raw SQL” with
node-pg
instead. Never looked back 😄 So that’s my advice, if you are able to. EDIT: Just to be clear, Typeorm is very good at a lot of stuff! But it did not play nice with Next.js in my experience. As this discussion we’re both a part of documents.I have a similar problem and maybe it will help you. check all your relations and change them as follows.