0
votes

I followed along the Configuration guide:

The module

@Module({
  providers: [
    {
      provide: ConfigService,
      useValue: new ConfigService(`development.env`),
    },
  ],
  exports: [ConfigService],
})
export class ConfigModule {}

The service:

export interface EnvConfig {
  [key: string]: string;
}
export class ConfigService {
  private readonly envConfig: EnvConfig;

  constructor(filePath: string) {
    console.log(filePath);
    const config = dotenv.parse(fs.readFileSync(filePath));
    this.envConfig = ConfigService.validateInput(config);
  }
[...]

whenever I run the app:

> nest start


development.env
[Nest] 10496   - 10/04/2019, 2:16:49 PM   [NestFactory] Starting Nest application...
undefined
[Nest] 10496   - 10/04/2019, 2:16:49 PM   [ExceptionHandler] The "path" argument must be one of ty
pe string, Buffer, or URL. Received type undefined +14ms
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL.
Received type undefined

It seems the service is instantiated 2 times. I don't know why. Any idea what's happening here?

1
And your ConfigService does only appear once in the providers array? No other module is providing it again? Can you show the module that is importing your ConfigModule resp. using your ConfigService?Kim Kern

1 Answers

1
votes

Accounting to our discussion on discord, you areproviding the ConfigService in your AppModule while also importing ConfigModule which leads Nest to think it needs to re-instantiate ConfigService but without the filePath variable for the constructor.

Removing the ConfigService from the providers array of the AppModule will resolve the problem.