typeorm-seeding icon indicating copy to clipboard operation
typeorm-seeding copied to clipboard

MODULE_NOT_FOUND - While im trying to use entity

Open Egzonrexhepi opened this issue 5 years ago • 2 comments

Hi

I recently installed typeorm-seeding into my project, and im trying to seed colors into a FormColorEntity,

My entity located in /src/form/form-color.entity.ts which is under FormModule

Here is my seeder:

import { Factory, Seeder } from 'typeorm-seeding'
import { Connection } from 'typeorm'
import { FormColorEntity } from 'src/form/form-color.entity'

export default class CreateUsers implements Seeder {
    public async run(factory: Factory, connection: Connection): Promise<any> {
        await connection
            .createQueryBuilder()
            .insert()
            .into(FormColorEntity)
            .values([
                { name: 'Timber' },
                { name: 'Phantom' },
            ])
            .execute();
    }
}

I am using only .env Config like this:


TYPEORM_SEEDING_FACTORIES=src/factories/**/*{.ts,.js}
TYPEORM_SEEDING_SEEDS=src/seeds/**/*{.ts,.js}

And my seeders are located in src/seeds/create-colors.seed.ts

Here is my package.json config:


  "seed:config": "ts-node ./node_modules/typeorm-seeding/dist/cli.js config",
    "seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"

Egzonrexhepi avatar Dec 02 '20 16:12 Egzonrexhepi

@Egzonrexhepi if you change your scripts to:

"seed:config": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js config",
"seed:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js seed"

if you add -r tsconfig-paths/register to the script will be able to run successfully.

I hope this can help you!

alefcastelo avatar Jan 06 '21 23:01 alefcastelo

The path to my ormconfig file is ./src/database/ormconfig.ts. so i rewrote the above as "seed:config": "ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -r=./src/database config" but when i run yarn seed:config I get:

$ ts-node -r tsconfig-paths/register ./node_modules/typeorm-seeding/dist/cli.js -r=./src/database config
🌱  TypeORM Seeding v1.6.1

❌  Could not find the orm config file
Error: Cannot find module './src/database/ormconfig.ts'

angelxmoreno avatar Jul 13 '21 07:07 angelxmoreno