How to build TS application that uses prismaGenerated files
Whenever my typescript project is compiled and built, I've noticed that the application is not outputting my prismaGenerated originally in the src directory into the build directory e.g. dist/project folder, if someone can help me navigate how it's normally done in production that'd be great thank you
1 Reply
You selected the bot's instantaneous insights. Let me compile your answer right away!
When building a TypeScript application that uses Prisma and generates the client (e.g., in
Use a script (e.g., in your
Some developers use tools like tsc-hooks to automate copying non-TypeScript files during the build process, but a simple copy script is often sufficient and more predictable for Prisma artifacts How to include schema.prisma in TypeScript output directory. 3. Update your imports:
Make sure your runtime code imports the Prisma client from the correct relative path in the build output (e.g.,
The standard practice is to copy the generated Prisma client directory into your build output as part of your build process, since TypeScript does not handle this automatically. This is a common pattern for Prisma in production deployments How to move Prisma Client in custom location to the dist folder when building for production?. If you need to include other files (like
src/prismaGenerated
), the TypeScript compiler (tsc
) only copies .ts
and .js
files to the output directory (like dist
). It does not automatically copy non-TypeScript files or folders such as your generated Prisma client.
Recommended approach:
1. Copy the generated Prisma client manually:Use a script (e.g., in your
package.json
) to copy the prismaGenerated
directory from src
to dist
after building. For example, you can add a postbuild
script:
This ensures the generated client is available in your build output and can be imported at runtime.
2. Alternative: Use a build tool or hook:Some developers use tools like tsc-hooks to automate copying non-TypeScript files during the build process, but a simple copy script is often sufficient and more predictable for Prisma artifacts How to include schema.prisma in TypeScript output directory. 3. Update your imports:
Make sure your runtime code imports the Prisma client from the correct relative path in the build output (e.g.,
dist/prismaGenerated
).
Summary:The standard practice is to copy the generated Prisma client directory into your build output as part of your build process, since TypeScript does not handle this automatically. This is a common pattern for Prisma in production deployments How to move Prisma Client in custom location to the dist folder when building for production?. If you need to include other files (like
schema.prisma
), use a similar copy approach.