Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeOrm migration - Error: Cannot find module

I'm trying npm run typeorm migration:run in my project and it is showing the error below.

Error during migration run: Error: Cannot find module 'src/permission/permission.entity'

Error during migratino run: Cannot find module 'permission'

ormconfig.js

module.exports = {
  type: 'mysql',
  host: 'localhost',
  port: 33066,
  username: 'root',
  password: '123456',
  database: 'admin',
  synchronize: false,
  entities: ['./src/**/*.entity.ts'],
  migrations: ['./src/migrations/*.ts'],
  cli: {
    entitiesDir: './ts/',
    migrationsDir: './src/migrations',
  },
};

What am I doing wrong? This is my git repo: https://github.com/wesoz/udemy-nest-admin/tree/td/seed

like image 681
Wes Oz Avatar asked Dec 21 '25 02:12

Wes Oz


2 Answers

You need to use a relative import path.

import { Permission } from '../permission/permission.entity';
like image 121
Camilo Avatar answered Dec 23 '25 15:12

Camilo


Using typeorm@^0.3.10

This worked for me. npm i -D tsconfig-paths

Adding this flag to the ts-node command -r tsconfig-paths/register

"migration:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run -d=ormconfig.ts"
like image 22
Vixson Avatar answered Dec 23 '25 16:12

Vixson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!