I am using NestJS and TypeORM and want to connect to my postgres database. But I am getting all kinds of errors. I am pretty sure it has to do with the ormconfig.ts and the entities in there. This is the file right now:
require('dotenv').config();
module.exports = {
host: process.env.DB_HOST,
type: 'postgres',
port: process.env.DB_PORT,
username: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
synchronize: true,
entities: [__dirname + '/../**/*.entity.{js,ts}'],
};
and I am getting SyntaxError: Cannot use import statement outside a module
Error in my Entity File that looks like this:
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class Software extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
description: string;
}
Fixes that I have tried:
- Adding
{
// ...
"type": "module",
// ...
}
to my package.json from this question "Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6
(then I get Object.defineProperty(exports, "__esModule", { value: true }); ReferenceError: exports is not defined
)
changing
entities: [__dirname + '/../**/*.entity.{js,ts}']
in the ormconfig.ts toautoLoadEntities: true,
, but then I getEntityMetadataNotFound: No metadata for "Software" was found.
not using the path, but instead do
entities: [Software]
in ormconfig.ts, but it doesnt like the import statementSyntaxError: Cannot use import statement outside a module
in the ormconfig.ts
It seems like everytime I fix one error, there is another one right away. Does anyone have any ideas as to why it might not work?