0

I'm using MikroOrm inside nestJs, and I added the following script inside package.json

"orm": "npx mikro-orm",

and these are the configurations

seeder: {
  path: 'src/misc/db/',
  defaultSeeder: 'DatabaseSeeder',
  glob: '!(*.d).{js,ts}',
  emit: 'ts',
  fileName: (className: string) => className,
}

I need to specify a specific seeder file when writing npm run orm seeder:run --class=ClassNameSeeder as the documentation mentioned, but I'm getting the following error

Unknown argument: ClassName

I tried also to run the following script in package.json and see if it'll work or not but I got the same error

"db:seed": "npm run mikro-orm seeder:run --class=ClassName"

Note

The seeder class is inside misc/db/ as I added it in my configuration file.

2 Answers2

1

I believe you are passing the --class into the npm run instead of mikro-orm commands. I dont think it makes much sense to have an NPM script as "orm": "npx mikro-orm", better to use npx directly, which won't suffer from this.

npx mikro-orm seeder:run --class=ClassNameSeeder

Alternatively, add -- when you call npm. Or use something smarter like yarn or pnpm, which also handles this automatically.

npm run orm seeder:run -- --class=ClassNameSeeder
Martin Adámek
  • 16,771
  • 5
  • 45
  • 64
-1

I have a similar setup as yours, and I just run the following script:

npm run orm seeder:run

This will seed your database using the seeder file src/misc/db/DatabaseSeeder.ts by default.

Do you have multiple files, hence the need to add the class argument ?
If so, Martin's answer is probably the best to follow.

Fabien
  • 21
  • 2