1

We're using Typescript, Prisma and TRPC in two NodeJS services that need to communicate with each other. Both services have their own database, so the generated Prisma client in node_modules is different between the folders. The folder structure is set up like so:

.
├── service_1/
│   ├── tsconfig.json
│   ├── package.json
│   └── ...rest of project
└── service_2/
    ├── tsconfig.json
    ├── package.json
    └── ...rest of project

Because we're using TRPC, service_1 imports types directly from service_2 like the following example:

import type { AppRouter } from '../../../../service_2/src/routers/index'

This works fine in VSCode, however we want to put typechecking as an CI action on service_1, but running tsc -p ./tsconfig.json --noEmit in the root of service_1 shows a lot of errors like this:

../service_2/src/services/dog.ts:53:10 - error TS2339: Property 'dog' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.

53   prisma.dog.findMany({

We surmise that this is caused by Typescript using the generated @prisma/client package from the service_1 folder even when typechecking service_2, but we've tried changing a number of options in our tsconfig.json to no avail.

Our current tsconfig.json in service_1 looks like this:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "strict": true,
    "paths": {
      "/*": ["./*"]
    },
    "baseUrl": "./",
    "noEmit": true,
    "esModuleInterop": true
  },
  "exclude": [
    "**/node_modules/*",
    "**/dist/*",
    "**/.git/*",
  ],
}

Some of the options we've tried include:

  • Setting rootDir to ./
  • Setting rootDir to ../
  • Setting rootDirs to ["./", "../service_2"]
  • Adding @ts-ignore or @ts-nocheck above the type import
  • Adding service_2 to the exclude option

Is there a way to get typechecking across two projects like this with separate node_modules on one that imports from another?

Ben Grant
  • 305
  • 6
  • 18
  • 2
    The `@prisma/client` namespace clash can be avoided by [generating the client to a custom path](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client#the-location-of-prisma-client) – Matt Jan 30 '23 at 01:55

0 Answers0