#Unable to Inject Service from Another Module into NestJS Service but Working in Controller

1 messages · Page 1 of 1 (latest)

tall grove
#

I'm encountering an issue where I can inject the PrismaService from another module into the ScreenshotController, but I am unable to inject it into the ScreenshotService. What could be causing this problem, and how can I resolve it?

prisma.service.ts

@Injectable()
export class PrismaService extends PrismaClient {}

prisma.module.ts

@Global()
@Module({
  providers: [PrismaService],
  exports: [PrismaService],
})
export class PrismaModule {
}

app.module.ts

@Module({
  imports: [
    PrismaModule,
    AuthModule,
    ScreenshotModule,
  ],
})
export class AppModule {}

screenshot.controller.ts

@Controller('screenshots')
@UseGuards(AuthGuard('auth0'))
export class ScreenshotController {
  constructor(
    private readonly screenshotService: ScreenshotService,
    private readonly prismaClient: PrismaService, // this works
  ) {}

screenshot.service.ts

@Injectable()
export class ScreenshotService {
  constructor(private readonly prismaService: PrismaService) {} // this fails

screenshot.module.ts

@Module({
  imports: [
    PrismaModule,
  ],
  controllers: [ScreenshotController],
  providers: [ScreenshotService],
})
export class ScreenshotModule {}
#

Error message

Error: Nest can't resolve dependencies of the ScreenshotService (?). Please make sure that the argument Object at index [0] is available in the ScreenshotModule context.

Potential solutions:
- Is ScreenshotModule a valid NestJS module?
- If Object is a provider, is it part of the current ScreenshotModule?
- If Object is exported from a separate @Module, is that module imported within ScreenshotModule?
  @Module({
    imports: [ /* the Module containing Object */ ]
  })
warm scroll
#

how did you import that PrismaService in the ScreenshotService file?

tall grove
#

Please check last two code snippets

#

I have included in the question

warm scroll
#

the import line

tall grove
#

Wtf 🤦‍♂️ thansk for the nudge, I was importing using import type now fixed

#

I wasted 2 days on this silly bug lol