#Prisma 6.6.0 ESM with Nx Monorepo - Typescript type check failures

21 messages · Page 1 of 1 (latest)

abstract cliff
#

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

sweet badgeBOT
#

You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!

abstract cliff
#

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

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

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/**/*",
  1. 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": []
}

And the reference int he app config:

"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)??

abstract cliff
#

I think maybe @copper idol 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
outer smelt
#

I don't get why they would release a version that doesn't support browser bundle 😭

vocal stone
#

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

copper idol
#

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.

nocturne night
#

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.

vocal stone
#

I'll see what I can do today in terms of a minimal reproduction

vocal stone
vocal stone
# copper idol A minimal reproduction would be very helpful here as version 6.6.0 was released ...

https://github.com/jensmeindertsma/prisma-client-debugging/tree/main absolutely minimal reproduction with documentation can be found here, i hope this helps

GitHub

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

frank sandal
copper idol
#

@vocal stone 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

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB - Issues · prisma/prisma

vocal stone
copper idol
#

Thanks for creating the issue. I am able to reproduce it based on your instructions 🙏

vocal stone