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

Question: Error inject repository after transpile #52

Open
vitordelfino opened this issue Jun 29, 2021 · 3 comments
Open

Question: Error inject repository after transpile #52

vitordelfino opened this issue Jun 29, 2021 · 3 comments

Comments

@vitordelfino
Copy link

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
Copy link
Author

@MWhite-22
Copy link

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

this link 404s. Can you fix?

@vitordelfino
Copy link
Author

repo is now public

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

this link 404s. Can you fix?

change repo to public

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

No branches or pull requests

2 participants