Skip to content
This repository was archived by the owner on Jul 15, 2026. It is now read-only.
This repository was archived by the owner on Jul 15, 2026. It is now read-only.

Losing dataSource on ResolveDataSource #3

Description

@the1alt

Hi,

I'm trying to use this package, using rockets-starter to understand it.
Each time I try to seed datas, I have this error message :

Cannot read properties of undefined (reading 'name') at new DataSource (/Users/piman/Sites/manitude/node_modules/typeorm/data-source/DataSource.js:46:29) at Object.resolveDataSource (/Users/piman/Sites/manitude/node_modules/@concepta/typeorm-seeding/dist/utils/resolve-data-source.js:8:90)

It seems that the object dataSource from 'this.options' is not accessible inside of the resolveDataSource function, even through it exists in the get dataSource()'s function of the seeding-source.js;

Or maybe I'm not creating my seedingSource object correctly.

seeding.ts

import { ApiConfigService } from "./common/api-config/api.config.service";

const { config } = require('dotenv');
const { SeedingSource } = require('@concepta/typeorm-seeding');
const { AppSeeder } = require('./app.seeder');
const { default: DataSource } = require('./ormconfig');

config();

const options = {
  DataSource,
  seeders: [AppSeeder],
  defaultSeeders: [AppSeeder],
}

module.exports =  new SeedingSource(options);

ormconfig.ts

import { DataSource } from 'typeorm';
import { ormConfigFactory } from './common/api-config/typeorm.config';

const source = new DataSource({
  ...ormConfigFactory()
});

export default source;

typeorm.config.ts

import { DataSourceOptions } from 'typeorm';
import { registerAs } from '@nestjs/config';

export const ormConfigFactory = (): DataSourceOptions => {
  return {
    migrationsTableName: 'migrations',
    name: 'default',
    type: 'mysql',
    host: 'localhost',
    port: 3306,
    username: 'myname',
    password: 'mypassword',
    database: 'mydb',
    logging: false,
    synchronize: false,
    entities: ['src/endpoints/**/**.entity{.ts,.js}'],
    migrations: ['dist/migration/**/*{.ts,.js}'],
  };
};

export const ormConfig = registerAs('TYPEORM_MODULE_CONFIG', ormConfigFactory);

plackage.json scripts

"seed:config": "typeorm-seeding config -r ./dist -c src/seeding.js",
    "seed:run": "typeorm-seeding seed -r ./dist -c src/seeding.js"

image

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions