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?
ConfigService
does only appear once in theproviders
array? No other module is providing it again? Can you show the module that is importing yourConfigModule
resp. using yourConfigService
? – Kim Kern