nmg49
nmg49

Reputation: 1386

Cannot Inject HttpConfigService in NestJS

I'm trying to set up an async config class for the HTTP Module as described in the documentation https://docs.nestjs.com/techniques/http-module#async-configuration.

@Injectable()
class HttpConfigService implements HttpModuleOptionsFactory {
  constructor() {}
  createHttpOptions(): HttpModuleOptions {
    return {
      timeout: 5000,
      maxRedirects: 5,
     };
  }
}

Then in my module:

imports: [
    ConfigModule.forRoot(), HttpConfigService, HttpModule.registerAsync({
        useClass: HttpConfigService,
    })
],

Despite trying to copy the pattern in the documentation, I get the following error:

Module '"./httpconfig.service"' declares 'HttpConfigService' locally, but it is not exported.ts(2459)

It seems like my custom HttpConfigService isn't getting injected properly. Would could be the cause of this? Is there something I'm doing wrong here?

Upvotes: 0

Views: 630

Answers (1)

Jay McDoniel
Jay McDoniel

Reputation: 70151

You need to add export to the class definition.

@Injectable()
export class HttpConfigService implements HttpModuleOptionsFactory {
  constructor() {}
  createHttpOptions(): HttpModuleOptions {
    return {
      timeout: 5000,
      maxRedirects: 5,
     };
  }
}

Upvotes: 1

Related Questions