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.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With