MyCommand.registerWithSubCommands() when subcommands are inside another module #817
-
Hello there 👋 I encountered an issue when trying to work with the method What we try to do is to provide & exports a @SubCommand({
name: "some-sub-command",
})
export class MySubCommand extends CommandRunner {
constructor(private readonly someProvider: SomeProvider) {
super();
}
public override run(): void {
// Do something ...
}
} Here is how it's instantiated through some random module : @Module({
imports: [SomeModule],
providers: [
SomeProvider,
{
provide: MySubCommand,
inject: [SomeProvider],
useFactory: (someProvider: SomeProvider): MySubCommand => {
return new MySubCommand(someProvider);
}
}
],
exports: [MySubCommand],
})
export class SomeModule {
} Here we have our command called @Command({
name: "my-command",
subCommands: [MySubCommand],
})
export class MyCommand extends CommandRunner {
public override run(): void {
// Do nothing
}
} And here is how we want to expose our CLI through our @Module({
imports: [SomeModule],
providers: [...MyCommand.registerWithSubCommands()],
})
export class CliModule {
} Our error when we try to run our application is that Nest can't resolve |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Could you get me a repository that has this setup? |
Beta Was this translation helpful? Give feedback.
Could you get me a repository that has this setup?
nest-commander
shouldn't be trying to make a new instance of that command, but it may be themoduleRef.get()
that is having issues