I'm trying to use TypeORM in Javascript node app but when I created my first Entity and tried to run the app I got Invalid or unexpected token
@Entity({ name: "application_users" })
SyntaxError: Invalid or unexpected token
at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:115:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:289:14)
Entity:
import { Entity, Column, PrimaryColumn } from "typeorm";
@Entity({ name: "application_users" })
export class User {
@PrimaryColumn()
id: String;
@Column()
biography: String;
@Column()
country: String;
@Column()
email: String;
@Column()
image: String;
}
Data Source:
export const AppDataSource = new DataSource({
type: "postgres",
url: process.env.DATABASE_URL,
logging: true,
synchronize: true,
entities: [User],
});
AppDataSource.initialize()
.then(() => console.log("Connected to DB"))
.catch((err) => console.error("Failed connecting to DB", err));
This is probably due using TypeScript syntax in JavaScript files.