typestack / typeorm-typedi-extensions

Dependency injection and service container integration with TypeORM using TypeDI library.
MIT License
262 stars 37 forks source link

Question: Error inject repository after transpile #52

Open vitordelfino opened 3 years ago

vitordelfino commented 3 years ago

When i start my application in develop mode, all works fine, but when transpile files. I use ts-node-dev to start app.

But when i transpile files with babel and start application, i get the error: UnhandledPromiseRejectionWarning: ParamTypeMissingError: Cannot get reflected type for a "repository" method's [object Object]1. parameter of OrderService class. Make sure you have turned on an "emitDecoratorMetadata": true, option in tsconfig.json. and that you have imported "reflect-metadata" on top of the main entry file in your application.And make sure that you have annotated the property type correctly with: Repository, MongoRepository, TreeRepository or custom repository class type.

emitDecoratorMetadata is true; reflect-metadata is imported;

File that start application server.ts

import 'reflect-metadata';
import { Container } from 'typedi';

import connection from '@config/db';
import { server } from '@config/globals';

import logger from '@middlewares/logger';
import { RabbitClient } from '@utils/rabbitmq/RabbitClient';

connection.then(async () => {
  Container.set(RabbitClient, new RabbitClient());
  const app = (await import('./app')).default;
  app.listen(server.port, () => {
    logger.info(`Server running`, server);
  });
});

OrderServive.ts

import { Inject, Service } from 'typedi';
import { InjectRepository } from 'typeorm-typedi-extensions';

import { dbConnections, rabbit } from './../../config/globals';
import { Order } from './order.entity';
import { OrderRepository } from './OrderRepository';
import { OrderStatus, TransactionStatus } from './types';

@Service()
export class OrderService {
  @InjectRepository(dbConnections.mongo.name)
  private repository!: OrderRepository;

  @Inject()
  private publisher!: RabbitPublisher;

  ....
}

OrderRepository.ts

import { EntityRepository, MongoRepository } from 'typeorm';

import { Order } from './order.entity';

@EntityRepository(Order)
export class OrderRepository extends MongoRepository<Order> {}
vitordelfino commented 3 years ago

github repo https://github.com/vitordelfino/stock-management

MWhite-22 commented 3 years ago

github repo https://github.com/vitordelfino/stock-management

this link 404s. Can you fix?

vitordelfino commented 3 years ago

repo is now public

github repo https://github.com/vitordelfino/stock-management

this link 404s. Can you fix?

change repo to public