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

#831 · open · 9 comments

View on GitHub ↗

nguyennhukhanh

## 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: ```json { "name": "New Category" } ``` ## Input Code > Entity ```ts 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 ```ts 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 ```ts 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 ```ts 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 ```ts 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 <pre><code> 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" </code></pre>

Comments

nguyennhukhanh

## **Error has been successfully fixed!** ## I downgraded nestjs ver and it's accessible. ```cmd "@nestjs/common": "^9.0.0", "@nestjs/core": "^9.0.0", "@nestjs/typeorm": "^9.0.0", "@nestjs/platform-express": "^9.0.0", ```

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

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 Ok, I will reopen this issue! Hopefully it will update to version 10 of NestJs

viiqswim

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

trocoli96

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

ckaeslin

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

hypesystem

Switching to [@dataui/crud](https://www.npmjs.com/package/@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:

geek-sajjad

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

hypesystem

@geek-sajjad this repo isn't maintained anymore. See the latest comments and switch to [@dataui/crud](https://www.npmjs.com/package/@dataui/crud)