Next.JS and TypeORM Issue
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hello, I'm trying to merge my Discord bot which uses TypeORM with my Next.JS Admin Panel. I made an index.ts file that i'm calling with
I have a problem with the decorators. I'm always getting errors such as:
I don't know what to do, I tried everything:
1. I set both experimentalDecorators and emitDecoratorMetadata in tsconfig.json to true.
2. Imported
3. Tried using babel and add plugins and such.
4. Explicitly told
None of the above worked. Why?
I'm in Next.JS Environment, inside
I omitted the part where I prepare the next app because it works perfectly fine.
GuildSettings Entity:
The only thing that worked which I don't wanna do is explicitly telling each Column its type (
Also, In the .tsx files themselves when importing the same entity it works. It only happens in the index.ts file and files that are outside the next app.
Before the merge, when starting the bot, it worked perfectly fine. Why does it do that in Next.JS's environment? Do I need to do something else do get it to work?
Thanks for your help!
tsx index.ts
.I have a problem with the decorators. I'm always getting errors such as:
ColumnTypeUndefinedError: Column type for Version#id is not defined and cannot be guessed. Make sure you have turned on an "emitDecoratorMetadata": true option in tsconfig.json. Also make sure you have imported "reflect-metadata" on top of the main entry file in your application (before any entity imported).If you are using JavaScript instead of TypeScript you must explicitly provide a column type.
I don't know what to do, I tried everything:
1. I set both experimentalDecorators and emitDecoratorMetadata in tsconfig.json to true.
2. Imported
reflect-metadata
at the top of the index.ts file, before any entity is imported.3. Tried using babel and add plugins and such.
4. Explicitly told
tsx
to use the tsconfig.json file from the root path of my Next.JS project.None of the above worked. Why?
I'm in Next.JS Environment, inside
src
folder I made a file index.ts
:import "reflect-metadata";
import { Guild } from './entity/Guild';
console.log(Guild);
I omitted the part where I prepare the next app because it works perfectly fine.
GuildSettings Entity:
import { Entity, PrimaryColumn, OneToOne, JoinColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
import { Guild } from './Guild';
@Entity()
export class GuildSettings {
@PrimaryColumn()
id: string;
@OneToOne(() => Guild, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'id' })
guild: Guild;
@Column({ default: 'r' })
prefix: string;
@CreateDateColumn({ type: 'timestamp' })
createdAt: Date;
@UpdateDateColumn({ type: 'timestamp' })
updatedAt: Date;
}
The only thing that worked which I don't wanna do is explicitly telling each Column its type (
@PrimaryColumn({ type: 'varchar' })
for example).Also, In the .tsx files themselves when importing the same entity it works. It only happens in the index.ts file and files that are outside the next app.
Before the merge, when starting the bot, it worked perfectly fine. Why does it do that in Next.JS's environment? Do I need to do something else do get it to work?
Thanks for your help!
1 Reply
Brown bearOP
Still relevant