After hours of digging, I need your help !
The context
I'm currently creating(early stage) an application with the stack : Nx(monorepo) + NestJS + TypeOrm
Here is my ormconfig file :
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "***",
"password": "****",
"database": "****",
"synchronize": false,
"logging":false,
"entities": ["apps/api/src/app/**/**.entity.ts"],
"migrations":["apps/api/src/migration/**.ts"],
"cli":{
"migrationsDir":["apps/api/src/migration"],
"entitiesDir":["apps/api/src/app/**/**.entity.ts"]
}
}
Here is my migration file :
import {MigrationInterface, QueryRunner, Table} from "typeorm";
export class users1573343025001 implements MigrationInterface {
public async up (queryRunner: QueryRunner): Promise<any> {
await queryRunner.createTable(new Table({
name: 'users',
columns: [
{ name: 'id', type: 'bigint', isPrimary: true,
isGenerated: true, generationStrategy: 'increment', unsigned: true },
{ name: 'username', type: 'varchar', isNullable: false },
{ name: 'password', type: 'varchar', isNullable: true },
]
}))
}
public async down (queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropTable('users')
}
}
The problem
When I run the command ng serve api to run my backend, I face this issue :
SyntaxError: Unexpected token {...
The error comes from my migration file : apps\api\src\migration\1573343025001-users.ts:1
What bugs me
If I run my migration with typeorm command, typeorm is able to run it without any trouble. Migration users1573343025001 has been executed successfully! So I don't understand why the migration file looks correct to my app during the migration but during the run.
What I have already tried
- A lot of answers around this topic are: change the migration dir to dist/migration. But I'm just trying to serve the app, not to build it.
- Recreate the file with typeorm command
- Verify that my package.json has the line :
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",to perform in typescript - npm install (Who knows?)
- Delete the migration and run the command ng serve api, the app started without any sign of error
I'm probably missing a basic thing with this technologies that are new to me. Hope all this is clear enough for you to understand the situation.
Thank You,
Séb