2

I think it's a typescript compilation problem but I'm still learning typescript. Here is some context, I'm using nestjs, prisma and vegardit/prisma-generator-nestjs-dto to create some rest cruds. I made a self relation of one to many but when I compile the project I get this error.

Cannot find module 'C:/sistema-gestion-riesgo/src/puesto/dto/connect-puesto.dto'
Require stack:
- C:\sistema-gestion-riesgo\dist\puesto\dto\create-puesto.dto.js
- C:\sistema-gestion-riesgo\dist\puesto\puesto.controller.js
- C:\sistema-gestion-riesgo\dist\puesto\puesto.module.js
- C:\sistema-gestion-riesgo\dist\app.module.js
- C:\sistema-gestion-riesgo\dist\main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.type (C:\sistema-gestion-riesgo\dist\puesto\dto\create-puesto.dto.js:15:57)
    at SchemaObjectFactory.mergePropertyWithMetadata (C:\sistema-gestion-riesgo\node_modules\@nestjs\swagger\dist\services\schema-object-factory.js:116:38)
    at C:\sistema-gestion-riesgo\node_modules\@nestjs\swagger\dist\services\schema-object-factory.js:79:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.extractPropertiesFromType (C:\sistema-gestion-riesgo\node_modules\@nestjs\swagger\dist\services\schema-object-factory.js:78:52)
    at SchemaObjectFactory.exploreModelSchema (C:\sistema-gestion-riesgo\node_modules\@nestjs\swagger\dist\services\schema-object-factory.js:92:41) 

This is the schema.prisma I'm using and it's configurations.

generator nestjsDto {
  provider                        = "prisma-generator-nestjs-dto"
  exportRelationModifierClasses   = "true"
  reExport                        = "true"
  createDtoPrefix                 = "Create"
  updateDtoPrefix                 = "Update"
  dtoSuffix                       = "Dto"
  entityPrefix                    = ""
  entitySuffix                    = ""
  fileNamingStyle                 = "kebab"
  output                          = "../src"
  outputToNestJsResourceStructure = "true"
}

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Puesto {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  nombre String
  /// @DtoCreateOptional
  /// @DtoUpdateOptional
  /// @DtoRelationCanConnectOnCreate
  /// @DtoRelationCanConnectOnUpdate
  jefeInmediato   Puesto?  @relation("JefeEmpleados", fields: [jefeInmediatoId], references: [id])
  jefeInmediatoId Int?
  personalAcargo  Puesto[] @relation("JefeEmpleados")
  @@map("puestos")
}

By last this is how the DTO's are generated.

connect-pruesto.dto.ts

export class ConnectPuestoDto {
  id: number;
}

create-puesto.dto.ts

import {ApiExtraModels} from '@nestjs/swagger'
import {ConnectPuestoDto} from './connect-puesto.dto'

export class CreatePuestoJefeInmediatoRelationInputDto {
    connect: ConnectPuestoDto;
  }

@ApiExtraModels(ConnectPuestoDto,CreatePuestoJefeInmediatoRelationInputDto)
export class CreatePuestoDto {
  nombre: string;
jefeInmediato?: CreatePuestoJefeInmediatoRelationInputDto;
}

And by last, index.ts

export * from './connect-puesto.dto';
export * from './create-puesto.dto';
export * from './update-puesto.dto';

2 Answers2

1

Delete dist folder and recompile or you can even hit npm i again .

0

It might be little bit late, but for future reference, I just had the same issue just a moment ago. Solved it by removing comments from schema models, recompiled and everything worked fine again.

henrbu
  • 137
  • 10