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.
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 file18 Replies
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the
#ask-ai
channel awaits if you're curious!NX project.json and tsconfig settings
In a specific file we have this import:
import {PrismaClient} from '@prisma/client-application'
Here is our project.json which uses esbuild
to build our project:
As you can see in project.json
file in the build
target in development
we also have type check and it uses the tsconfig.app.json
file.
Here is the tsconfig.app.json
:
The tsconfig.base.json
has these rules (as part of many):
erasableSyntaxOnly, exactOptionalPropertyTypes and noUnusedLocals
The type check fails as it checks also the files in @prisma/client-application
. Not sure why the heck this is happening as these files are in my node_modules folder.
What I tried so far?
1. Adding an external
entry of "external": ["@prisma/client-application/index.js"]
tot he project.json
file.
2. Adding to the exclude
section of the tsconfig.app.json
file:
3. Adding a new tsconfig.override.json
with ts references from the tsconfig.app.json
file that looks like this:
And the reference int he app config:
but seems like esbuild
does not respect any of references, or maybe I'm doing something wrong.
How can I overcome this WITHOUT turning off type check in development mode (using skipTypeCheck: true
)??
I think maybe @Nurul (Prisma) could assist here? 🙂
The main problem is that the ESM option does not follow the same strict rules we follow in our repo and so this is causing us major issues.
"erasableSyntaxOnly": true,
"exactOptionalPropertyTypes": true,
"noUnusedLocals": true@Nurul (Prisma) Shouldn't the new ESM option also generte its
.d.ts
files? WOuldn't that resolve the issue?
https://github.com/microsoft/TypeScript/issues/40426#issuecomment-1373167253GitHub
Disable type checking for node_modules entirely · Issue #40426 · ...
Search Terms skipLibCheck node_modules ignore library exclude Suggestion Either a new option or the existing option skipLibCheck should be able to disable type checking for node_modules. Use Cases ...
I also found this:
https://www.prisma.io/docs/orm/prisma-schema/overview/generators#limitations
Can this just be a bug at the moment?
Even if fixed (removeing namespaces for example), why not also generate .d.ts file to resolve it?
Generators (Reference) | Prisma Documentation
Generators in your Prisma schema specify what assets are generated when the
prisma generate
command is invoked. This page explains how to configure generators.I don't get why they would release a version that doesn't support browser bundle 😭
i ran into typechecking errors with the new generated client, compiling of the application using it with vite (esm) works fine, application performs normal, but ‘tsc’ fails because of the namespaces. when i find some time ill try making a more minimal reproduction but for now i hope they remove these troublesome typescript code in the next release
A minimal reproduction would be very helpful here as version 6.6.0 was released this week and there might be some cases in which esm doesn't work as expected.
I'll be able to share the reproduction with ORM team and debug.
Also cant pass typechecks when running 6.6.0. Went back to 6.5.0. There is a huge line (runetimedatamodel) which is given a typeerror in the client.ts file.
I'll see what I can do today in terms of a minimal reproduction
I have figured out the root cause: these type errors appear as soon as one enables
"composite": true
(https://www.typescriptlang.org/tsconfig/#composite) in the tsconfig.json file
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
One must also switch to use
Project References
(https://www.typescriptlang.org/docs/handbook/project-references.html)Documentation - Project References
How to split up a large TypeScript project
https://github.com/jensmeindertsma/prisma-client-debugging/tree/main absolutely minimal reproduction with documentation can be found here, i hope this helps
GitHub
GitHub - jensmeindertsma/prisma-client-debugging: A minimal reprodu...
A minimal reproduction for TypeScript type checking problems occuring in the new "generated client" that comes with Prisma 6.6.0. - jensmeindertsma/prisma-client-debugging
getting the same issue (as well as all others mentioned above)
@juniperxxd Thank you for creating a reproduction. Do you mind creating a GitHub Issue as well?
https://github.com/prisma/prisma/issues/
I'll share it with ORM team internally
GitHub
Issues · prisma/prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - Issues · prisma/prisma
https://github.com/prisma/prisma/issues/26902 done, sorry it took a bit 🙂 , hope this helps, I'm available for further questions
GitHub
Prisma Client 6.6.0 uses TypeScript features incompatible with `"co...
Bug description When using TypeScript Project References, it is required to set "composite": true as a compilerOption in the tsconfig.json file: Referenced projects must have the new comp...
Thanks for creating the issue. I am able to reproduce it based on your instructions 🙏
great, thanks for picking it up! 🙂
Thanks for reporting the issue, we plan to fix this soon in upcoming releases