I have an express app with "typeorm": "^0.3.16", . I used the data source configuration and now I want to generate migrations for the entities I've provided in data source :
db.ts
import { DataSource } from "typeorm";
import { Brand } from "@entity/brand.entity";
export const dataSource = new DataSource({
type: "mysql",
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
database: process.env.DB,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
logging: false,
synchronize: false,
migrations: ["../migration/**/*.ts"],
migrationsRun: true,
entities: [Brand],
});
And this is the command I run trying to generate migrations for the Brand entity :
"migration:generate": "typeorm migration:generate PostRefactoring -d src/config/db.ts"
But it gives me error :
Error during migration generation:
Error: Unable to open file: "/Users/mehdi/Desktop/zhivarteb-backend/src/config/db.js". Cannot use import statement outside a module
How can I generate typeorm migrations based on data source config file for provided entities in node js express ?
typefield inpackage.json. Try to addtype: 'module'topackage.json. However I'm afraid that running migrations is not related to the error you get.