Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nguyennhukhanh opened this issue Aug 23, 2023 · 9 comments

Comments

@nguyennhukhanh
Copy link

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
Copy link
Author

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",

@mertsafter
Copy link

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

@nguyennhukhanh
Copy link
Author

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

@viiqswim
Copy link

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

ngovanxuanduc added a commit to ngovanxuanduc/crud that referenced this issue Sep 29, 2023
@trocoli96
Copy link

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

@ckaeslin
Copy link

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

@hypesystem
Copy link

hypesystem commented Nov 2, 2023

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 😄

@geek-sajjad
Copy link

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

@hypesystem
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants