#strange object expected as provider
34 messages · Page 1 of 1 (latest)
/show-the-error (it's not deployed yet 😁)
there isn't much of a error would have shared if there was
just If Object is a provider, is it part of the current AppModule?
but pointed that out already
nest seems to expect a provider called object
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.
never knew that
here is the full thing then
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)
now we need to see the constructor of AccountService
constructor(
private readonly emailService: EmailService,
private config: ApiConfigService,
private readonly tokenService: TokenService,
private readonly prisma: ExtendedPrismaClient,
) {}
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)
that is a complicated matter
it is related to this threat post #1171400491696140328 message
where typescript would't accept extended prisma methods
got it
this typing is then exported and used what you now see
you'd have to use custom providers or an abstract class, if you want to avoid the @Inject() in your case
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.
type IExtendedPrismaClient = ReturnType<PrismaService['setup']>
abstract class ExtendedPrismaClient extends IExtendedPrismaClient {}
should work
ah was about to ask because i didn't fully understand your response
'IExtendedPrismaClient' only refers to a type, but is being used as a value here.
just don't use IExtendedPrismaClient as a value :p
that's why you have ExtendedPrismaClient now
isn't that was you exactly mentioned here
oh, yeah
due to the extends, right
yes
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
seems like an interesting issue https://github.com/prisma/prisma/issues/18628
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
oh that's a intresting thing will have to look into it
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
thanks for pointing this one out