PrismaP
Prisma10mo ago
21 replies
Kazaz

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


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
Was this page helpful?