**TLDR: **
Booting an application that uses registerAsync() on a dynamic module fails to resolve dependencies, always at index 0, no matter how I order the injection list, no matter what I inject:
Nest can't resolve dependencies of the CONFIGURABLE_MODULE_OPTIONS[c0eb100884e61f001eea2] (?, Symbol(NAME), Symbol(VERSION), Symbol(INSTANCE_ID)). Please make sure that the argument Symbol(APP_OPTIONS) at index [0] is available in the CustomModule context.
Detailed version:
On NestJS 10.0.5, I have a custom dynamic module (in an NPM package) that uses
import { ConfigurableModuleBuilder } from "@nestjs/common";
import { type ModuleOptions } from "../lib/ModuleOptions.interface.js";
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN } =
new ConfigurableModuleBuilder<ModuleOptions>().build();
and
import { DiscoveryModule } from "@golevelup/nestjs-discovery";
@Module({
imports: [DiscoveryModule],
providers: [...], // there are almost exclusively FactoryProviders, some with OnModuleInit and OnApplicationBootstrap, here
})
export class CustomModule extends ConfigurableModuleClass {}
Then, in my actual Application, I have
@Module({
imports: [
ConfigModule,
appMetadataModule, // provides injection tokens NAME, VERSION, INSTANCE_ID
CustomModule.registerAsync({
inject: [APP_OPTIONS, NAME, VERSION, INSTANCE_ID],
useFactory: (appOptions: AppOptions, name: string, version: string, instanceId: string) => {
return ...;
},
}),
],
providers: [appOptionsFactory] // depends on ConfigModule
})
export class MyApplicationModule {}
When booting the application, I get the error
Nest can't resolve dependencies of the CONFIGURABLE_MODULE_OPTIONS[c0eb100884e61f001eea2] (?, Symbol(NAME), Symbol(VERSION), Symbol(INSTANCE_ID)). Please make sure that the argument Symbol(APP_OPTIONS) at index [0] is available in the CustomModule context.