P
Prisma2w ago
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"
}
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
18 Replies
Prisma AI Help
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
Kazaz
KazazOP2w ago
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:
{
"name": "jobs-service",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"tags": ["scope:jobs"],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "development",
"options": {
"platform": "node",
"outputPath": "dist/apps/jobs-service",
"main": "src/main.ts",
"format": ["esm"],
"tsConfig": "{projectRoot}/tsconfig.app.json",
"deleteOutputPath": true,
"bundle": true,
"generatePackageJson": true,
"minify": false,
"outputHashing": "none",
"thirdParty": false
},
"configurations": {
"development": {
"sourcemap": true,
"declaration": true,
"skipTypeCheck": false
},
"production": {
"sourcemap": false,
"declaration": false,
"skipTypeCheck": true
}
},
"dependsOn": [
{
"projects": ["prisma-schemas"],
"target": "generate:application"
}
]
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "jobs-service:build:development",
"runBuildTargetDependencies": true,
"watch": true,
"debounce": 100,
"inspect": true,
"port": 9229,
"host": "localhost"
},
"configurations": {
"production": {
"buildTarget": "jobs-service:build:production"
}
}
}
}
}
{
"name": "jobs-service",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"tags": ["scope:jobs"],
"targets": {
"build": {
"executor": "@nx/esbuild:esbuild",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "development",
"options": {
"platform": "node",
"outputPath": "dist/apps/jobs-service",
"main": "src/main.ts",
"format": ["esm"],
"tsConfig": "{projectRoot}/tsconfig.app.json",
"deleteOutputPath": true,
"bundle": true,
"generatePackageJson": true,
"minify": false,
"outputHashing": "none",
"thirdParty": false
},
"configurations": {
"development": {
"sourcemap": true,
"declaration": true,
"skipTypeCheck": false
},
"production": {
"sourcemap": false,
"declaration": false,
"skipTypeCheck": true
}
},
"dependsOn": [
{
"projects": ["prisma-schemas"],
"target": "generate:application"
}
]
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "jobs-service:build:development",
"runBuildTargetDependencies": true,
"watch": true,
"debounce": 100,
"inspect": true,
"port": 9229,
"host": "localhost"
},
"configurations": {
"production": {
"buildTarget": "jobs-service:build:production"
}
}
}
}
}
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:
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "../../dist/apps/jobs-service",
"types": ["node"],
"tsBuildInfoFile": "../../dist/apps/jobs-service/tsconfig.lib.tsbuildinfo"
},
"include": ["src/**/*.ts"],
"exclude": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.mock.ts"
],
"references": [
{
"path": "../../packages/environments/tsconfig.lib.json"
},
{
"path": "../../packages/utils/tsconfig.lib.json"
},
{
"path": "./tsconfig.override.json"
}
]
}
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "../../dist/apps/jobs-service",
"types": ["node"],
"tsBuildInfoFile": "../../dist/apps/jobs-service/tsconfig.lib.tsbuildinfo"
},
"include": ["src/**/*.ts"],
"exclude": [
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.mock.ts"
],
"references": [
{
"path": "../../packages/environments/tsconfig.lib.json"
},
{
"path": "../../packages/utils/tsconfig.lib.json"
},
{
"path": "./tsconfig.override.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:
"../../node_modules/@prisma/**/*",
"../../node_modules/@prisma/**/*",
3. Adding a new tsconfig.override.json with ts references from the tsconfig.app.json file that looks like this:
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"erasableSyntaxOnly": false,
"exactOptionalPropertyTypes": false,
"noUnusedLocals": false
},
"include": ["../../node_modules/@prisma/**/*"],
"exclude": []
}
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"erasableSyntaxOnly": false,
"exactOptionalPropertyTypes": false,
"noUnusedLocals": false
},
"include": ["../../node_modules/@prisma/**/*"],
"exclude": []
}
And the reference int he app config:
"references": [
{
"path": "./tsconfig.override.json"
}
]
"references": [
{
"path": "./tsconfig.override.json"
}
]
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
Kazaz
KazazOP2w ago
@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-1373167253
GitHub
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 ...
Kazaz
KazazOP2w ago
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.
Yagodi
Yagodi2w ago
I don't get why they would release a version that doesn't support browser bundle 😭
juniperxxd
juniperxxd2w ago
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
Nurul
Nurul2w ago
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.
DennisK
DennisK2w ago
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.
juniperxxd
juniperxxd2w ago
I'll see what I can do today in terms of a minimal reproduction
juniperxxd
juniperxxd2w ago
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.
juniperxxd
juniperxxd2w ago
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
juniperxxd
juniperxxd2w ago
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
h3llo
h3llo2w ago
getting the same issue (as well as all others mentioned above)
Nurul
Nurul7d ago
@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
juniperxxd
juniperxxd7d ago
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...
Nurul
Nurul6d ago
Thanks for creating the issue. I am able to reproduce it based on your instructions 🙏
juniperxxd
juniperxxd5d ago
great, thanks for picking it up! 🙂
Nurul
Nurul5d ago
Thanks for reporting the issue, we plan to fix this soon in upcoming releases

Did you find this page helpful?