title: Import another module's repository in my module in nestjs
body: <p>I'm trying to build an application with Nestjs and currently I have two modules: User and Auth with following structure:</p>
  
  <p><a href="https://i.stack.imgur.com/N8Zyz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/N8Zyz.png" alt="enter image description here"></a></p>
  
  <p>I needed to inject <strong>UsersService</strong> into <strong>AuthService</strong> in order to interact with <strong>User</strong> entity, so first I've injected <strong>UsersRepository</strong> into <strong>UsersService</strong> and exported the service:</p>
  
  <p>users.module.ts:</p>
  
  <pre><code>import { Module } from '@nestjs/common';
  import { UsersService } from './users.service';
  import { TypeOrmModule } from '@nestjs/typeorm';
  import { UserRepository } from './user.repository';
  
  @Module({
    imports: [
      TypeOrmModule.forFeature([UserRepository]),
    ],
    providers: [
      UsersService,
      UserRepository,
    ],
    exports: [
      UsersService,
      TypeOrmModule,
    ],
  })
  export class UsersModule {}
  </code></pre>
  
  <p>users.service.ts:</p>
  
  <pre><code>import { Injectable } from '@nestjs/common';
  import { AuthCredentialsDto } from '../auth/dto/auth-credentials.dto';
  import { JwtPayload } from '../auth/jwt-payload.interface';
  import { User } from './user.entity';
  import { InjectRepository } from '@nestjs/typeorm';
  import { UserRepository } from './user.repository';
  
  @Injectable()
  export class UsersService {
    constructor(
      @InjectRepository(UserRepository)
      private userRepository: UserRepository,
    ) {}
  
    async signUp(authCredentialsDto: AuthCredentialsDto): Promise&lt;void&gt; {
      return this.userRepository.signUp(authCredentialsDto);
    }
  
    async validateUserPassword(authCredentialsDto: AuthCredentialsDto): Promise&lt;string&gt; {
      return this.userRepository.validateUserPassword(authCredentialsDto);
    }
  
    async findOne({ username }: JwtPayload): Promise&lt;User&gt; {
      return this.userRepository.findOne({ username });
    }
  }
  </code></pre>
  
  <p>users.repository.ts:</p>
  
  <pre><code>import { ConflictException, Injectable, InternalServerErrorException } from '@nestjs/common';
  import * as bcrypt from 'bcrypt';
  import { Repository, EntityRepository } from 'typeorm';
  import { User } from './user.entity';
  import { AuthCredentialsDto } from '../auth/dto/auth-credentials.dto';
  
  @Injectable()
  @EntityRepository(User)
  export class UserRepository extends Repository&lt;User&gt; {
    async signUp(authCredentialsDto: AuthCredentialsDto): Promise&lt;void&gt; {
      const { username, password } = authCredentialsDto;
  
      const salt = await bcrypt.genSalt();
      const user = new User();
      user.username = username;
      user.password = await this.hashPassword(password, salt);
      user.salt = salt;
  
      try {
        await user.save();
      } catch (error) {
        if (error.code === '23505') {
          throw new ConflictException('Username already exists');
        } else {
          throw new InternalServerErrorException();
        }
      }
    }
  
    async validateUserPassword(authCredentialsDto: AuthCredentialsDto): Promise&lt;string&gt; {
      const { username, password } = authCredentialsDto;
      const user = await this.manager.findOne(User, { username });
  
      if (user &amp;&amp; await user.validatePassword(password)) {
        return user.username;
      } else {
        return null;
      }
    }
  
    private async hashPassword(password: string, salt: string): Promise&lt;string&gt; {
      return bcrypt.hash(password, salt);
    }
  }
  </code></pre>
  
  <p>Issue is when I need to call a <strong>UserService</strong> methods from <strong>AuthService</strong>, I'll get error with following format:</p>
  
  <pre><code>[Nest] 6267   - 11/08/2019, 3:30:52 AM   [ExceptionsHandler] Cannot read property 'findOne' of undefined +4600ms
  TypeError: Cannot read property 'findOne' of undefined
      at UserRepository.validateUserPassword (/home/firiz/Projects/giftos/api/dist/users/user.repository.js:35:41)
      at UsersService.validateUserPassword (/home/firiz/Projects/giftos/api/dist/users/users.service.js:26:36)
      at AuthService.signIn (/home/firiz/Projects/giftos/api/dist/auth/auth.service.js:24:49)
      at AuthController.signIn (/home/firiz/Projects/giftos/api/dist/auth/auth.controller.js:26:33)
      at /home/firiz/Projects/giftos/api/node_modules/@nestjs/core/router/router-execution-context.js:37:29
      at process._tickCallback (internal/process/next_tick.js:68:7)
  
  </code></pre>
  
  <p>My question is... what I'm missing, causing this painful issue!</p>