Как только я меняю с
import { UsersService } from '../users/users.service';
на
import { CreateAuthDto, UsersService } from './index';
Возникает ошибка
[Nest] 10368 - 07.01.2022, 14:12:57 ERROR [ExceptionHandler] Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument dependency at index [0] is available in the AuthModule context.
Potential solutions:
- If dependency is a provider, is it part of the current AuthModule?
- If dependency is exported from a separate @Module, is that module imported within AuthModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})
Error: Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument dependency at index [0] is available in the AuthModule context.
Potential solutions:
- If dependency is a provider, is it part of the current AuthModule?
- If dependency is exported from a separate @Module, is that module imported within AuthModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})
at Injector.resolveSingleParam (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\injector.js:141:19)
at resolveParam (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\injector.js:108:49)
at Array.map (<anonymous>)
at Injector.resolveConstructorParams (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\injector.js:123:58)
at Injector.loadInstance (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\injector.js:52:20)
at Injector.loadProvider (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\injector.js:74:20)
at Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\instance-loader.js:44:62
at Array.map (<anonymous>)
at InstanceLoader.createInstancesOfProviders (Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\instance-loader.js:44:36)
at Y:\projects\appnest3\app\node_modules\@nestjs\core\injector\instance-loader.js:29:24
import { Module } from '@nestjs/common';
import { UsersModule, AuthController, AuthService } from './index';
@Module({
imports: [UsersModule],
controllers: [AuthController],
providers: [AuthService],
})
export class AuthModule {}
import { Module } from '@nestjs/common';
import { PrismaService } from '../shared/prisma.service';
import { UsersService } from './users.service';
@Module({
providers: [UsersService, PrismaService],
exports: [UsersService],
})
export class UsersModule {}
export * from './auth.service';
export * from './auth.controller';
export * from '../users/users.module';
export * from '../users/users.service';
export * from './dto/create-auth.dto';
import { BadRequestException, Injectable } from '@nestjs/common';
import { User } from '@prisma/client';
import * as bcrypt from 'bcrypt';
//import { UsersService } from '../users/users.service'; //работает норм
//import { CreateAuthDto } from './dto/create-auth.dto';
import { CreateAuthDto, UsersService } from './index'; //ошибка
@Injectable()
export class AuthService {
private user: User;
public constructor(private readonly usersService: UsersService) {}
public async register(
createAuthDto: CreateAuthDto,
): Promise<User | BadRequestException> {
this.user = await this.usersService.findOne({ email: createAuthDto.email });
if (this.user && this.user.email === createAuthDto.email) {
throw new BadRequestException('Choose another email');
}
createAuthDto.password = await bcrypt.hash(createAuthDto.password, 12);
return await this.usersService.create(createAuthDto);
}
}