配置设置:“ path”参数必须是类型[…]之一。接收的类型未定义

问题描述 投票:0回答:1

我跟随Configuration guide

模块

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

服务:

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);
  }
[...]

每当我运行应用程序时:

> 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

似乎该服务已实例化2次。我不知道为什么知道这里发生了什么吗?

nestjs
1个回答
0
投票
根据我们对不和的讨论,您是providing中的ConfigService,而[[也是AppModuleimporting导致Nest认为需要重新实例化ConfigModule,但构造函数没有ConfigService变量。

filePathConfigService阵列中删除providers将解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.