nestjs typeError: configService.get is not a function
时间: 2023-07-06 11:43:33 浏览: 52
这个错误通常是因为没有正确注入 `ConfigService` 这个模块。在 NestJS 中,`ConfigService` 是通过依赖注入来使用的,需要在模块中正确注入它,然后在需要使用的地方进行调用。
请确保在你的模块中正确地导入了 `ConfigModule` 并将其添加到 `imports` 数组中。示例代码如下:
```typescript
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [ConfigModule.forRoot()],
controllers: [AppController],
providers: [AppService, ConfigService],
})
export class AppModule {}
```
在上面的代码中,我们将 `ConfigModule` 导入到了 `AppModule` 中,并将 `ConfigService` 添加到了 `providers` 数组中,这样它就可以被依赖注入到其他的组件中了。
如果你已经正确注入了 `ConfigService`,那么你可能需要检查 `ConfigModule` 的导入路径是否正确,或者你可能需要重新安装 `@nestjs/config` 这个模块。