crud icon indicating copy to clipboard operation
crud copied to clipboard

ERROR [ExceptionsHandler] Cannot read properties of null (reading 'options')

Open nguyennhukhanh opened this issue 1 year ago • 9 comments

Bug Report

[Nest] 14964  - 08/24/2023, 12:15:56 AM   ERROR [ExceptionsHandler] Cannot read properties of null (reading 'options')
TypeError: Cannot read properties of null (reading 'options')
    at CategoryService.createOne (\node_modules\@nestjsx\crud-typeorm\src\typeorm-crud.service.ts:118:35)
    at CategoryController.createOneBase (\node_modules\@nestjsx\crud\src\crud\crud-routes.factory.ts:227:27)
    at \node_modules\@nestjs\core\router\router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Current behavior

I use to create a new Category. Here is describing it in json:

{
  "name": "New Category"
}

Input Code

Entity

import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  DeleteDateColumn,
  OneToMany,
} from 'typeorm';

import { Product } from './product.entity';

@Entity('category')
export class Category {
  @Column({ name: 'id', type: 'bigint' })
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'name', nullable: false })
  name: string;

  @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  CreatedAt: Date;

  @CreateDateColumn({ name: 'updated_at', type: 'timestamp' })
  UpdatedAt: Date;

  @DeleteDateColumn({ name: 'deleted_at', nullable: true })
  DeletedAt?: Date;

  @OneToMany(() => Product, (product) => product.category)
  products: Product[];
}

Controller

import { Controller } from '@nestjs/common';
import { Crud, CrudController } from '@nestjsx/crud';
import { ApiTags } from '@nestjs/swagger';

import { CategoryService } from './category.service';
import { CreateCategoryDto, UpdateCategoryDto } from './dto/category.dto';

import { Category } from '../../database/entity/category.entity';

@ApiTags('category')
@Crud({
  model: {
    type: Category,
  },
  dto: {
    create: CreateCategoryDto,
    update: UpdateCategoryDto,
  },
  query: {
    join: {
      products: {
        eager: true,
      },
    },
  },
  routes: {
    only: [
      'getManyBase',
      'getOneBase',
      'createOneBase',
      'updateOneBase',
      'deleteOneBase',
    ],
  },
})
@Controller('category')
export class CategoryController implements CrudController<Category> {
  constructor(public service: CategoryService) {}
}

Service

import { Injectable } from '@nestjs/common';
import { TypeOrmCrudService } from '@nestjsx/crud-typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';

import { Category } from '../../database/entity/category.entity';

@Injectable()
export class CategoryService extends TypeOrmCrudService<Category> {
  constructor(@InjectRepository(Category) repository: Repository<Category>) {
    super(repository);
  }
}

Module

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { CategoryController } from './category.controller';
import { CategoryService } from './category.service';

import { Category } from '../../database/entity/category.entity';

@Module({
  imports: [TypeOrmModule.forFeature([Category])],
  controllers: [CategoryController],
  providers: [CategoryService],
})
export class CategoryModule {}

DTO

import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class CreateCategoryDto {
  @ApiProperty()
  @IsNotEmpty()
  @IsString()
  name: string;
}

export class UpdateCategoryDto {
  @ApiProperty()
  @IsOptional()
  @IsString()
  name?: string;
}

Expected behavior

I expected it to create a new category with the corresponding name!

Environment


Package version: 0.0.1

 
For Tooling issues:
- Node version: v18.16.0
- Platform:  Windows
- Database: Postgres

Other:
- "@nestjs/common": "^10.0.0"
- "@nestjs/core": "^10.0.0"
- "@nestjs/typeorm": "^10.0.0"
- "pg": "^8.11.2"
- "@nestjsx/crud": "^5.0.0-alpha.3"
- "@nestjsx/crud-typeorm": "^5.0.0-alpha.3"

nguyennhukhanh avatar Aug 23 '23 17:08 nguyennhukhanh

Error has been successfully fixed!

I downgraded nestjs ver and it's accessible.

     "@nestjs/common": "^9.0.0",
     "@nestjs/core": "^9.0.0",
     "@nestjs/typeorm": "^9.0.0",
     "@nestjs/platform-express": "^9.0.0",

nguyennhukhanh avatar Aug 24 '23 13:08 nguyennhukhanh

Can we reopen this? I don't think that a downgrade of nestjs should be the solution to this. I am trying to make this work using nestjs 10 but without success. Seems like the library has to be adjusted to the changes made in nestjs 10

mertsafter avatar Sep 02 '23 21:09 mertsafter

Can we reopen this? I don't think that a downgrade of nestjs should be the solution to this. I am trying to make this work using nestjs 10 but without success. Seems like the library has to be adjusted to the changes made in nestjs 10

Ok, I will reopen this issue! Hopefully it will update to version 10 of NestJs

nguyennhukhanh avatar Sep 13 '23 14:09 nguyennhukhanh

I'm having the same problem. nestjsx/crud doesn't work with NestJS v10 😢

viiqswim avatar Sep 19 '23 00:09 viiqswim

Same problem here! I see the commit, does someone know release date?

trocoli96 avatar Oct 16 '23 14:10 trocoli96

We have switched to https://github.com/gid-oss/dataui-nestjs-crud which is a fork and works for us with nestjs 10.

ckaeslin avatar Oct 17 '23 07:10 ckaeslin

Switching to @dataui/crud as @ckaeslin suggests fixed this for me.

The problem is an unmaintained, unofficial package that has fallen out of sync with nestjs.

I personally took over a project from other people and didn't notice the x in @nestjsx which was a cause of a lot of confusion here :smile:

hypesystem avatar Nov 02 '23 23:11 hypesystem

any update on this issue ? should i switch to other forked repo ?

geek-sajjad avatar Nov 06 '23 19:11 geek-sajjad

@geek-sajjad this repo isn't maintained anymore. See the latest comments and switch to @dataui/crud

hypesystem avatar Nov 07 '23 09:11 hypesystem