#strange object expected as provider

34 messages · Page 1 of 1 (latest)

waxen portal
#

ok i have been trying to debug this for a while, most of my code is disabled at this moment
there are several points in my code nest seems to expect a provider called object the 2 sources seems to be accountService and a global guard registered in the app.module

void wing
#

/show-the-error (it's not deployed yet 😁)

waxen portal
void wing
#

The full message includes where nest found the issue, which would point to a place/class where we'd need to have a look at the constructor.

hallow palm
waxen portal
#
Nest can't resolve dependencies of the AccountService (EmailService, ApiConfigService, TokenService, ?). Please make sure that the argument Object at index [3] is available in the AppModule context.

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

Error: Nest can't resolve dependencies of the AccountService (EmailService, ApiConfigService, TokenService, ?). Please make sure that the argument Object at index [3] is available in the AppModule context.

Potential solutions:
- Is AppModule a valid NestJS module?
- If Object is a provider, is it part of the current AppModule?
- If Object is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing Object */ ]
  })
#
    at Injector.lookupComponentInParentModules (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:254:19)
    at Injector.resolveComponentInstance (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:207:33)
    at resolveParam (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:128:38)
    at async Promise.all (index 3)
    at Injector.resolveConstructorParams (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:143:27)
    at Injector.loadInstance (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:70:13)
    at Injector.loadProvider (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/injector.js:97:9)
    at /home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/instance-loader.js:56:13
    at async Promise.all (index 4)
    at InstanceLoader.createInstancesOfProviders (/home/weshuiz13/Documents/nest-server/node_modules/@nestjs/core/injector/instance-loader.js:55:9)
hallow palm
#

now we need to see the constructor of AccountService

waxen portal
hallow palm
#

so I can only say that ExtendedPrismaClient is a type, not a class

#

or it is being imported as a type-only (via import type)

#

and you can confirm that by adding @Inject(ExtendedPrismaClient)

waxen portal
hallow palm
#

got it

waxen portal
#

this typing is then exported and used what you now see

hallow palm
#

you'd have to use custom providers or an abstract class, if you want to avoid the @Inject() in your case

livid flowerBOT
#

This post has been marked as resolved. :white_check_mark:
Please read through the conversation and resolution if you are having the same issue, and then re-open the post if you are still having trouble, providing as much extra information as possible.

hallow palm
#
type IExtendedPrismaClient = ReturnType<PrismaService['setup']>
abstract class ExtendedPrismaClient extends IExtendedPrismaClient {}

should work

waxen portal
waxen portal
hallow palm
#

just don't use IExtendedPrismaClient as a value :p

#

that's why you have ExtendedPrismaClient now

waxen portal
hallow palm
#

oh, yeah
due to the extends, right

waxen portal
hallow palm
#

stick with @Inject(SomeToken) then

#

or you can hacky around like this:

// @ts-ignore
abstract class ExtendedPrismaClient implements IExtendedPrismaClient {}

I think this is fair because you know that the token ExtendedPrismaClient will be used for the extended prisma client

fringe sphinx
#

I feel like you could make a more elegant solution using declaration merging but im not sure out of the top of my head how thats going to look like. Perhaps there's even a prisma generator to help with this?

#

The proxy in your constructor approach could be another way I suppose

waxen portal
#

the solution of https://github.com/prisma/prisma/issues/18628#issuecomment-1601937737
seems to be interesting as particular as they create a prisma instance in a function
then run this function in the prismaService constructor and type cast

GitHub

Problem Within NestJS, the common solution to implementing an injectable Prisma Client instance is to extend PrismaClient and add the onModuleInit and enableShutdownHooks functions required by Nest...

waxen portal