Im trying to import a Module with registerAsync and configure it with a provider I have in my module, but it throws an error it cant find this provider. What am I missing?
My Code:
import { CacheModule, Module } from '@nestjs/common';
@Module({
imports: [
CacheModule.registerAsync({
useFactory: async (options) => ({
ttl: options.ttl,
}),
inject: ['MY_OPTIONS'],
}),
],
providers: [
{
provide: 'MY_OPTIONS',
useValue: {
ttl: 60,
},
},
],
})
export class AppModule {
}
Error:
Error: Nest can't resolve dependencies of the CACHE_MODULE_OPTIONS (?). Please make sure that the argument MY_OPTIONS at index [0] is available in the CacheModule context.
The example above is a simplification of my code. But the main issue stays the same: I do have a provider within the AppModule and I need it in the CacheModule.registerAsync() function.
If anyone wants to try figuring this out I made a really simple repository: https://github.com/MickL/nestjs-inject-existing-provider