Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NestJS Prisma Generated Types Not Included in dist folder

I'm working on a NestJS backend and using Prisma for my database. I generated my Prisma type with the following configuration:

generator clientTypes {
  provider = "prisma-client-js"
  output   = "../ts-rest/types/generated/client"
}

I'm using ts-rest to share the same types between my frontend and backend. I need to import an enum from Prisma like this:

import { CUSTOMER_TYPE } from "ts-rest/types/generated/client";

However, when I try to compile, I get a MODULE_NOT_FOUND error in the file where this import is used. If I change the import path to "@prisma/client", the error is resolved, but I can't use that in my frontend. I use nest start --watch to compile directly my code.

After some research, I found that the issue occurs because the generated Prisma types are not included in the dist/ts-rest folder after compilation so in the compiled code the type is not present.

Why aren't the Prisma-generated types being copied to the dist folder, and how can I resolve this?

I already tried modifying nest-cli.json, with this:

"compilerOptions": {
    "assets": ["ts-rest/types/generated/**/*"]
  }

but that didn't fix the issue.

like image 936
benoit Avatar asked Nov 22 '25 21:11

benoit


1 Answers

Inside your nest-cli.json make the folder path according to yours and this will copy the generated prisma folder into the dist folder

{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "assets": [
      {
        "include": "../prisma/generated/**/*",
        "outDir": "./dist/prisma",
        "watchAssets": true
      },
      {
        "include": "../prisma/schema.prisma",
        "outDir": "./dist/prisma",
        "watchAssets": true
      },
      {
        "include": "../prisma/generated/**/*",
        "outDir": "./dist/prisma"
      }
    ],
    "watchAssets": true
  }
}
like image 197
Yoko Hailemariam Avatar answered Nov 24 '25 18:11

Yoko Hailemariam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!