Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: factory not found on runtime #1019

Open
simon-tannai opened this issue Jun 8, 2024 · 4 comments
Open

Bug: factory not found on runtime #1019

simon-tannai opened this issue Jun 8, 2024 · 4 comments

Comments

@simon-tannai
Copy link

Versions

  • Node: 20
  • OS: Docker Alpine

Reproduction

Additional Details Commands:
{
    "cli": "node ./dist/apps/cli/main",
    "cli:dev": "ts-node ./apps/cli/src/main"
}

Datasource:

private readonly options: DataSourceOptions & SeederOptions = {
    ...databaseConfig,
    factories: [join(__dirname, '..', '..', '..', '..', 'apps', 'my-app', 'src', '**', '*.factory{.ts,.js}')],
    seeds: [MainSeeder],
}

Steps to reproduce

I'm using nest-commander to create a CLI application to seed a database into a production-like environment.

In dev' env', the seeding is working well. But in production-like env' (after TS build), it's not working.

It looks typeorm-extension is not working without ts-node ?

What is Expected?

Running seeds into production-like environment without ts-node.

What is actually happening?

Error: No seeder factory is registered for the entity: MyEntity
@simon-tannai
Copy link
Author

In the other hand, it's working well when I'm importing manually all the entities and factories:

  private readonly options: DataSourceOptions & SeederOptions = {
    ...databaseConfig,
    entities: [
      MyFirstEntity,
      [...]
      MySecondEntity,
    ],
    factories: [
      MyFirstFactory,
      [...]
      MySecondFactory,
    ],
    seeds: [MainSeeder],
  }

@IB3N
Copy link

IB3N commented Jul 2, 2024

+1

@tada5hi
Copy link
Owner

tada5hi commented Jul 2, 2024

Can you please provide a repository for reproduction.

@rostoriginal
Copy link

rostoriginal commented Oct 10, 2024

+1

This stopped working when I updated to version 3.6.2; everything was working correctly with version 3.6.1.

Node 20.18.0
OS: Windows 11
Framework: NestJS

{
"@nestjs/common": "^10.4.4",
    "@nestjs/config": "^3.2.3",
    "@nestjs/core": "^10.4.4",
    "@nestjs/platform-express": "^10.4.4"
    "@nestjs/typeorm": "^10.0.2",
}
Sample of my code which run seeder:

function runSeeder(seeder: string) {
  try {
    console.log(`Run seeder: ${seeder}`);
    execSync(
      `ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run -d ./src/db/data-source.ts -n ${seeder}`,
      { stdio: 'inherit' },
    );
  } catch (error) {
    console.error(`Error run seeder ${seeder}:`, error);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants