When attempting to import a Module using registerAsync and configuring it with a provider from my module, I encounter an error stating that the provider cannot be found. Can anyone help identify what I am missing?
Here is my code snippet:
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 message received:
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 provided example simplifies my actual code, but the core issue remains: I have a provider within the AppModule that needs to be accessed in the CacheModule.registerAsync() function.
If anyone would like to assist in troubleshooting this problem, I have created a simple repository here: https://github.com/MickL/nestjs-inject-existing-provider