ARTICLE AD BOX
I have UsersService provided + exported from UsersModule, and AuthModule imports UsersModule, but Nest still throws:
Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument UsersService at index [0] is available in the AuthModule context.I checked that the module wiring looks correct:
users.module.ts
import { Module } from '@nestjs/common'; import { UsersService } from './users.service'; @Module({ providers: [UsersService], exports: [UsersService], }) export class UsersModule {}auth.module.ts
import { Module } from '@nestjs/common'; import { AuthService } from './auth.service'; import { UsersModule } from '../users/users.module'; @Module({ imports: [UsersModule], providers: [AuthService], }) export class AuthModule {}But in auth.service.ts I accidentally imported UsersService from the compiled output (or another path) instead of the same source module:
auth.service.ts
import { Injectable } from '@nestjs/common'; // ⚠️ Notice: importing from dist (or a different path) instead of ../users/users.service import { UsersService } from '../../dist/users/users.service'; @Injectable() export class AuthService { constructor(private readonly usersService: UsersService) {} }Even though the class name is the same (UsersService), Nest still can’t resolve it.
Why does importing the same service from a different path (like dist/... vs src/...) break NestJS DI?
How can I prevent this (monorepo, path aliases, build output, lint rules), and what’s the best practice to ensure the injection token matches the provider token?
