I'm trying to build a console helper with NestJS that works with a Mongoose database.
To build the Mongoose URI, I have created my own module which creates the URI for me.
When I start the application normally, everything works as it should and the DatabaseService is injected and in this service I can access the ConfigService inside of my database.service.ts.
But, when I call the CLI tool and start the app with
const app = await NestFactory.createApplicationContext(AppModule);
I get the following error:
[Nest] 18400 - 22.08.2024, 16:53:40 ERROR [ExceptionHandler] Cannot read properties of undefined (reading 'getOrThrow')
TypeError: Cannot read properties of undefined (reading 'getOrThrow')
at DatabaseService.getDatabaseUrl ([PATH]\src\module\database\database.service.ts:14:37)
at InstanceWrapper.useFactory ([PATH]\src\app.module.ts:19:30)
at Injector.instantiateClass ([PATH]\node_modules\@nestjs\core\injector\injector.js:368:55)
at callback ([PATH]\node_modules\@nestjs\core\injector\injector.js:65:45)
at async Injector.resolveConstructorParams ([PATH]\node_modules\@nestjs\core\injector\injector.js:144:24)
at async Injector.loadInstance ([PATH]\node_modules\@nestjs\core\injector\injector.js:70:13)
at async Injector.loadProvider ([PATH]\node_modules\@nestjs\core\injector\injector.js:97:9)
at async [PATH]\node_modules\@nestjs\core\injector\instance-loader.js:56:13
at async Promise.all (index 3)
at async InstanceLoader.createInstancesOfProviders ([PATH]\node_modules\@nestjs\core\injector\instance-loader.js:55:9)
Replication/Example
my-console-tool.ts
async function bootstrap() {
const app = await NestFactory.createApplicationContext(AppModule);
... my code ...
app.close();
}
bootstrap();
Issue type:
nestjs-config version "@nestjs/config": "3.2.3"
@nestjs/common+core or other package versions
Excepted behavior
I'm trying to build a console helper with NestJS that works with a Mongoose database. To build the Mongoose URI, I have created my own module which creates the URI for me. When I start the application normally, everything works as it should and the DatabaseService is injected and in this service I can access the ConfigService inside of my
database.service.ts
.main.ts call:
const app = await NestFactory.create(AppModule);
Actual behavior or outcome (for issue)
But, when I call the CLI tool and start the app with
const app = await NestFactory.createApplicationContext(AppModule);
I get the following error:Replication/Example
my-console-tool.ts
app.module.ts
database.module.ts
database.service.ts