Denys
Denys

Reputation: 21

Object literal may only specify known properties, and 'cli' does not exist in type TypeOrmModuleOptions

I'm trying to set up migrations in my Nest JS project along with the cli, but no matter what I do, typeorm always swears on the cli. It's been many days and I'm stumped.

enter image description here

error TS2322: Type '{ type: "postgres"; host: string; port: number; username: string; database: string; password: string; entities: string[]; migrations: string[]; cli: { migrationsDir: string; }; extra: { charset: string; }; synchronize: false; logging: true; }' is not assignable to type 'TypeOrmModuleOptions'. Object literal may only specify known properties, and 'cli' does not exist in type '{ retryAttempts?: number; retryDelay?: number; toRetry?: (err: any) => boolean; autoLoadEntities?: boolean; keepConnectionAlive?: boolean; verboseRetryLog?: boolean; } & Partial'.

Upvotes: 2

Views: 5820

Answers (2)

Vadim Setsko
Vadim Setsko

Reputation: 11

  1. You ORM config should be instance of DataSource ormconfig.ts file like this:

    export default new DataSource({ type: 'postgres', host: process.env.POSTGRES_HOST port: +process.env.POSTGRES_PORT, username: process.env.POSTGRES_USER, password: process.env.POSTGRES_DB_PASSWORD, database: process.env.POSTGRES_DATABASE, entities: [__dirname + '//*.entity{.ts,.js}'], synchronize: false, migrations: [__dirname + '/migrations//*{.ts,.js}'], });

add to package.json next commands:

"typeorm": "ts-node -P tsconfig.json ./node_modules/typeorm/cli.js",
"db:drop": "yarn run typeorm schema:drop -d src/ormconfig.ts",
"db:gen": "yarn run typeorm migration:generate src/migrations/migration -d src/ormconfig.ts",
"db:migrate": "yarn run typeorm migration:run -- -d src/ormconfig.ts"

Upvotes: 0

linusw
linusw

Reputation: 1310

If you use typeorm 0.3.x, typeorm-cli needs migration path as a command option now. You can delete that part typescript complains and check this thread. TypeORM/nest - running migrations with `useFactory`

Upvotes: 0

Related Questions