dmitriy-nz / nestjs-form-data

NestJS middleware for handling multipart/form-data, which is primarily used for uploading files.
https://www.npmjs.com/package/nestjs-form-data
MIT License
112 stars 23 forks source link

Error: Nest can't resolve dependencies of the FormDataInterceptor (?) #54

Open VermilionB opened 7 months ago

VermilionB commented 7 months ago

I tryed to use your library, but got an error: Error: Nest can't resolve dependencies of the FormDataInterceptor (?). Please make sure that the argument Symbol(Inject token for NestJsFormData global configuration object) at index [0] is available in the BeatsModule context.

Here is my BeatsModule:


import { Module } from '@nestjs/common';
import { BeatsController } from './beats.controller';
import { BeatsService } from './beats.service';
import {PrismaService} from "../prisma.service";
import {FileUploadService} from "../file-upload/file-upload.service";
import {AvatarGeneratorService} from "../avatar_generator/avatar_generator.service";

@Module({
  controllers: [BeatsController],
  providers: [BeatsService, PrismaService, FileUploadService, AvatarGeneratorService]
})
export class BeatsModule {}
dmitriy-nz commented 7 months ago

Hi @VermilionB Check if main the module is connected, add the NestjsFormDataModule to your BeatsModule in imports section. Details in doc:

wershest commented 7 months ago

I've got same error when I use NestjsFormDataModule.configAsync(). The NestjsFormDataModule.config() is ok. This is my AppModule:

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: `.env.${process.env.NODE_ENV}`,
    }),
    MongooseModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        uri: config.get<string>('DB_URL'),
      }),
    }),
    // this is ok
    // NestjsFormDataModule.config({
    //   isGlobal: true,
    //   storage: FileSystemStoredFile,
    //   fileSystemStoragePath: '/tmp/nest-starter',
    // }),

    // configAsync cause errors
    NestjsFormDataModule.configAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        isGlobal: true,
        storage: FileSystemStoredFile,
        fileSystemStoragePath: config.get<string>('TEMP_DIR'),
      }),
    }),
    UsersModule,
    AuthModule,
  ],
  controllers: [],
  providers: [
    {
      provide: APP_PIPE,
      useValue: new ValidationPipe({ transform: true }),
    },
  ],
})
export class AppModule {}

Error: Nest can't resolve dependencies of the FormDataInterceptor (?). Please make sure that the argument Symbol(Inject token for NestJsFormData global configuration object) at index [0] is available in the UsersModule context.

abriginets commented 5 months ago

Hi @VermilionB Check if main the module is connected, add the NestjsFormDataModule to your BeatsModule in imports section. Details in doc:

Docs says it needs to be imported on the app level while in reality it's not global by default and needs to be imported on module basis.

jamalahmed1122 commented 1 month ago

@wershest is correct, and i also solve the issue by using config instead of configAsync