Using latest version of TypeORM: 0.3.9 with NestJS.
While I'm trying to generate migration with following command:
npm run typeorm migration:generate -- ./migrations/Init -o -d ormconfig.js
Getting error:
Error during migration generation:
Error: Given data source file must contain export of a DataSource instance
Here is my DataSource file:
ormconfig.js
var dbConfig = {
synchronize: false,
migrations: ['migrations/*.js'],
cli: {
migrationsDir: 'migrations',
},
};
switch (process.env.NODE_ENV) {
case 'development':
Object.assign(dbConfig, {
type: 'sqlite',
database: 'db.sqlite',
entities: ['**/*.entity.js'],
});
break;
case 'test':
Object.assign(dbConfig, {
type: 'sqlite',
database: 'test.sqlite',
entities: ['**/*.entity.ts'],
migrationsRun: true,
});
break;
case 'production':
Object.assign(dbConfig, {
type: 'postgres',
url: process.env.DATABASE_URL,
migrationsRun: true,
entities: ['**/*.entity.js'],
ssl: {
rejectUnauthorized: false,
},
});
break;
default:
throw new Error('unknown environment');
}
module.exports = dbConfig;

Also TypeORM script snippet from:
package.json
"scripts": {
"typeorm": "cross-env NODE_ENV=development node --require ts-node/register ./node_modules/typeorm/cli.js"
},