1

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 ?

3
  • The error you're facing is perhaps related to type field in package.json. Try to add type: 'module' to package.json. However I'm afraid that running migrations is not related to the error you get. Commented Jun 4, 2023 at 16:24
  • @EmadMamaghani I tried and still getting this error . Commented Jun 4, 2023 at 16:29
  • 1
    Check this stackoverflow.com/questions/59435293/… Commented Jun 4, 2023 at 16:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.