Closed tonydspaniard closed 11 months ago
Looks like this https://github.com/golevelup/nestjs/issues/499 issue, but I also tried creating a dynamic root module:
import { Module } from '@nestjs/common';
import { AWS_MODULE_CONFIG_TOKEN, AWS_S3_CLIENT_TOKEN } from './constants';
import * as ClientS3 from '@aws-sdk/client-s3';
import { S3 } from '@aws-sdk/client-s3';
import { createConfigurableDynamicRootModule } from '@golevelup/nestjs-modules';
import { AwsModuleConfig } from './aws-vendor.interfaces';
import { AwsS3Service } from './aws-vendor-s3.service';
@Module({})
export class AwsVendorProviderModule extends createConfigurableDynamicRootModule<AwsVendorProviderModule, AwsModuleConfig>(
AWS_MODULE_CONFIG_TOKEN,
{
providers: [
{
provide: AWS_S3_CLIENT_TOKEN,
useFactory: ({ s3 }: AwsModuleConfig): S3 => {
return new S3(<ClientS3.S3ClientConfig>s3);
},
inject: [AWS_MODULE_CONFIG_TOKEN]
},
AwsS3Service
],
exports: [AWS_MODULE_CONFIG_TOKEN, AWS_S3_CLIENT_TOKEN, AwsS3Service]
}
) {
}
Added to the App.Module, but when I try to use the AwsS3Service
that contains the decorator, it fails even if I add AwsVendorProviderModule.externallyConfigured(AwsVendorProviderModule, 0),
to the module that contains the issue. It gotta be something very simple, but I cannot figured it out...
I solved doing the following, that looks to me like a hack:
@Inject(forwardRef(() => AwsS3Service))
Currently works, but I feel this is a hack. If you have a better solution I am all ears. Thank you!
Found the problem, the issue was to make use of path aliases within the structure of the application, changing them to relative paths everything works.
First of all, I would like to apologize if this questions seems too newbie in the advanced concepts of NestJs but I am going a bit nuts trying to figure out what is going on.
I have created a decorator:
I have added the declaration of it into a dynamic root module:
When I run the tests, all is working:
But then, when I plug the module into my app.module and I want to use the decorator in a service:
I tried the above solutions, I looked into how you created the stripe client, and is exactly the same. What am I missing?