English 中文(简体)
with罐无法找到模块
原标题:Nestjs with prisma cannot find module

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-riesgodistpuestodtocreate-puesto.dto.js
- C:sistema-gestion-riesgodistpuestopuesto.controller.js
- C:sistema-gestion-riesgodistpuestopuesto.module.js
- C:sistema-gestion-riesgodistapp.module.js
- C:sistema-gestion-riesgodistmain.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-riesgodistpuestodtocreate-puesto.dto.js:15:57)
    at SchemaObjectFactory.mergePropertyWithMetadata (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:116:38)
    at C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:79:35
    at Array.map (<anonymous>)
    at SchemaObjectFactory.extractPropertiesFromType (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:78:52)
    at SchemaObjectFactory.exploreModelSchema (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:92:41) 

这是schema.prisma。 I m使用并配置。

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")
}

归根结底,如何产生DTO。

-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 ;
问题回答

删除碎块和 re子,或者你甚至可以再次打一只。

也许不太晚了,但就未来而言,我刚才也存在同样的问题。 通过从化学模型中删除评论、重新编造和一切照旧来解决这一问题。

In my case, there was cross combinations of .js and .ts files added in the project caused this issue. once it s updated to same type of files (eg. .js / .ts), it started working.





相关问题
Working with modules in IntelliJ IDEA

As I understand, using modules allows us to control some dependencies. I mean that we can allow one module to interact with another one but not vise versa. We also can make some reusable things and ...

Module import path

I m unable to test-run a cssparser that I d like to use. test.py: from css.parse import parse data = """ em { padding: 2px; margin: 1em; border-width: medium; border-style: ...

Problem modulating action script project

I am refactoring a hugh action script solution in Flash builder (beta 2) using the flex 4 sdk. The project does NOT use the mx framework. What i want to have is: A big MAIN project several small ...

Test modules with Test::Unit

I encountered a problem when trying to test a module with Test::Unit. What I used to do is this: my_module.rb: class MyModule def my_func 5 # return some value end end test_my_module.rb: ...

Drupal section accessible by role

I need to limit access of content on Drupal site based on the Drupal User s Role. http://site.com/managers/intro http://site.com/managers/reviews http://site.com/managers/up-for-raises The ...

How to find where a function was imported from in Python?

I have a Python module with a function in it: == bar.py == def foo(): pass == EOF == And then I import it into the global namespace like so: from bar import * So now the function foo is ...

How to wire two modules in Verilog?

I have written two modules DLatch and RSLatch and i want to write verilog code to join those two.

热门标签