Kazaz
Kazaz
PPrisma
Created by Kazaz on 4/10/2025 in #help-and-questions
Prisma 6.6.0 ESM with Nx Monorepo - Typescript type check failures
The message is too long, so the rest of it is in the replies Prisma: 6.6.0 Repo: monorepo using NX and esbuild version: 20.6.2 Package manager: pnpm with workspaces Type: module (ESM and not CommonJS) Problem statment: esbuild try to run typecheck on the auto generated prisma files and fails due to strict rules in our repo (erasableSyntaxOnly, exactOptionalPropertyTypes and noUnusedLocals). These files are in the main node_modules (with skipLibCheck: true. Why the heck esbuild and nx even try to check them??? Prisma settings We're using the newly generator that supports ESM as the commonJS one is causing build issues due to use of require in its files.
generator client {
provider = "prisma-client"
output = "../../../../../node_modules/@prisma/client-application"
previewFeatures = []
moduleFormat = "esm"
}
generator client {
provider = "prisma-client"
output = "../../../../../node_modules/@prisma/client-application"
previewFeatures = []
moduleFormat = "esm"
}
And importing the client like this: import {PrismaClient} from '@prisma/client-application' Requirements We're using nx to manage our mono repo and the prisma schema types needs to be shared across different projects/apps. Therefore, it's located in a shared location with an output to the main node_modules of the repo. Also the migration files will be generated there. Here is our folder structure |-- package.json |-- nx.json |-- node_modules |---- @prisma |-------- client |------------ index.js |-------- client-application |------------ index.ts |------------ client.ts |-- apps/jobs-service/ |---- tsconfig.json |---- tsconfig.app.json |---- project.json # nx project file |-- databases/prisma-schemas/src/lib/ |---- application/ # Application domain |-------- migrations/ # Application-specific migrations |-------- schema.application.prisma # Application schema file |---- [domain]/ # Additional domain |-------- migrations/ # Domain-specific migrations |-------- schema.[domain].prisma # Domain schema file
22 replies
PPrisma
Created by Kazaz on 2/12/2025 in #help-and-questions
queryRaw plsql function failed Code: `42601`. Message: `ERROR: syntax error at or near "$1"`
Hi everyone, I'm trying to call a function in my Postgres DB with this signature:
CREATE OR REPLACE FUNCTION main.create_brand_global_search_mv(brand_id TEXT) RETURNS TEXT AS $$
CREATE OR REPLACE FUNCTION main.create_brand_global_search_mv(brand_id TEXT) RETURNS TEXT AS $$
It gets the brand ID as a variable. Using Prisma I'm not able to call it no matter what I do: queryRaw executeRaw queryRawUnsafe executeRawUnsafe (this is in our tests so no fear of SQL injection) Here is an example:
const sql = `SELECT main.create_brand_global_search_mv('${brand.id}');`;
await prismaClient.$queryRawUnsafe(sql);
const sql = `SELECT main.create_brand_global_search_mv('${brand.id}');`;
await prismaClient.$queryRawUnsafe(sql);
brand.id is a UUID string. I get this error all the time with all approaches:
Invalid `prisma.$queryRaw()` invocation:

Raw query failed. Code: `42601`. Message: `ERROR: syntax error at or near "$1"`
Invalid `prisma.$queryRaw()` invocation:

Raw query failed. Code: `42601`. Message: `ERROR: syntax error at or near "$1"`
Even when I use the unsafe approach the error seems to happen in the queryRaw function (or executeRaw if I try and use executeRawUnsafe). I also tried using Prisma.raw as was suggested in some Github repo and it didn't work: https://github.com/prisma/prisma/issues/13162#issuecomment-1675434494 How can I make it work? I assumed that I could run everything I wanted with the unsafe approaches but seems like it's not working. It is worth mentioning that if I take the SQL string and run it directly on the DB it does work. Prisma version: 5.22.0
5 replies