nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.1k stars 541 forks source link

Cannot destructure property 'parsed' of 'req' as it is null. #830

Closed neutron92 closed 1 year ago

neutron92 commented 1 year ago

Bug Report

Current behavior

when i open http://localhost:3333/users in my browser to get list of users i have 500 and the error in the console

image

in the POST

image

The req argument all the time is null

Input Code

// controller
@Crud({
  model: {
    type: User,
  },
  query: {
    alwaysPaginate: true,
  },
  serialize,
  dto,
  validation: {
    transform: true,
  },
})
@Feature('users')
@ApiTags('users')
@Controller('users')
export class UsersController implements CrudController<User> {
  constructor(public service: UsersService) {}
}

//Module
@Module({
  imports: [TypeOrmModule.forFeature([User])],
  controllers: [UsersController],
  providers: [UsersService],
})
export class UsersModule {}

//Service
@Injectable()
export class UsersService extends TypeOrmCrudService<User> {
  constructor(@InjectRepository(User) readonly repo) {
    super(repo);
  }
}

//Main
CrudConfigService.load();

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, {
    cors: true,
  });

  app.useGlobalFilters(new HttpExceptionFilter());
  app.use(cookieParser());
  app.use(json({ limit: '150mb' }));
  app.use(urlencoded({ extended: true, limit: '150mb' }));

  SwaggerConfig(app, AppModule.apiVersion);

  await app.listen(AppModule.port, AppModule.host);
}
bootstrap();

Expected behavior

it works

Possible Solution

Environment


image

Repository with minimal reproduction

lan-nguyen91 commented 1 year ago

@neutron92 , how did you fix this issue ?

neutron92 commented 1 year ago

I'm struggling with updating nestjs to v10 in existing project and hit the wall with this repo not being maintained anymore. There is a fork that looks well maintained here: https://github.com/gid-oss/dataui-nestjs-crud

henrytsui commented 1 year ago

i face same issue, please reopen this issue

fsoubes commented 1 year ago

Same here Do you have any news to bypass this issue ?

neutron92 commented 1 year ago

I'm struggling with updating nestjs to v10 in existing project and hit the wall with this repo not being maintained anymore. There is a fork that looks well maintained here: https://github.com/gid-oss/dataui-nestjs-crud

MikhaelGerbet commented 1 year ago

I'm struggling with updating nestjs to v10 in existing project and hit the wall with this repo not being maintained anymore. There is a fork that looks well maintained here: https://github.com/gid-oss/dataui-nestjs-crud

saved my project bud ! Thx

khiami commented 1 year ago

Overriding the base route fixes the issue!.. but I mean this is not a proper fix.. since I believe we're are not supposed to override unless there's a reason. The latest update I think breaks the chain where @Controller extends the class.

danielsharvey commented 8 months ago

The underlying cause is https://github.com/nestjsx/crud/issues/825. My workaround (from here):

If you are using @rewiko/crud, use patch-package to handle the NestJS change.

For context, this is the issue: https://github.com/nestjs/nest/pull/11450 (a constant CUSTOM_ROUTE_AGRS_METADATA was misspelt a while back and finally removed - the correct spelling is now used - CUSTOM_ROUTE_ARGS_METADATA).

Here is my patch:

@rewiko+crud+5.1.12.patch

ihazar commented 8 months ago

Same issue here also:

ERROR [ExceptionsHandler] Cannot destructure property 'parsed' of 'req' as it is null.
TypeError: Cannot destructure property 'parsed' of 'req' as it is null.
    at ScanMetadataService.getMany (/node_modules/@nestjsx/crud-typeorm/src/typeorm-crud.service.ts:99:13)
    at ScanMetadataController.getManyBase (/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:215:27)
    at /node_modules/@nestjs/core/router/router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

I downgraded from nestjs 10.3.3 to 9.4.3 @nestjs/core@9.4.3 @nestjs/common@9.4.3 and it worked.

Or of course, use a more maintained crud library as mentioned above:

npm uninstall @nestjsx/crud @nestjsx/crud-typeorm
npm i --save @dataui/crud @dataui/crud-typeorm

And change all imports from '@nestjsx/crud' and from '@nestjsx/crud-typeorm' to '@dataui/crud' and '@dataui/crud-typeorm'respectively.