jmcdo29 / nest-commander

A module for using NestJS to build up CLI applications
https://nest-commander.jaymcdoniel.dev/
MIT License
435 stars 53 forks source link

CommandFactory is not compatible with Mongoose integration for NestJS #982

Closed gganebnyi closed 1 year ago

gganebnyi commented 1 year ago

Is there an existing issue for this?

Current behavior

When MongooseModule is used, an attempt to run the project results in

[Nest] 91872  - 07/03/2023, 3:31:50 PM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the MongooseCoreModule context.

Minimum reproduction code

app.module.ts

import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

@Module({
  imports: [
    MongooseModule.forRoot('mongodb://viar_user:M0ng0Pass%23ord%21@sl4.fusionworks.md:27017/'),
  ],
})
export class AppModule { }

main.ts

import { CommandFactory } from 'nest-commander';
import { AppModule } from './app.module';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';

async function bootstrap() {
  console.log('start');
  // const app = await NestFactory.create(AppModule)
  const app = await CommandFactory.createWithoutRunning(AppModule, ['warn', 'error', 'debug', 'log']);
  console.log('done');
}

bootstrap();

Console output

[Nest] 91872  - 07/03/2023, 3:31:50 PM   ERROR [ExceptionHandler] Nest can't resolve dependencies of the MongooseCoreModule (MongooseConnectionName, ?). Please make sure that the argument ModuleRef at index [1] is available in the MongooseCoreModule context.

Potential solutions:
- Is MongooseCoreModule a valid NestJS module?
- If ModuleRef is a provider, is it part of the current MongooseCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within MongooseCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

Expected behavior

Everything initialised as if using NestFactory.create

Package

Package version

^2.4.0

Node.js version

16

In which operating systems have you tested?

Other

No response

jmcdo29 commented 1 year ago

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

why reproductions are required

jmcdo29 commented 1 year ago

I'll re-open this if I receive a reproduction