w3tecch / typeorm-seeding

🌱 A delightful way to seed test data into your database.
https://www.npmjs.com/package/typeorm-seeding
MIT License
887 stars 132 forks source link

MODULE_NOT_FOUND - While im trying to use entity #103

Open Egzonrexhepi opened 3 years ago

Egzonrexhepi commented 3 years ago

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"
alefcastelo commented 3 years ago

@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!

angelxmoreno commented 3 years ago

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'