question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple prisma with nx workspaces and nestjs

See original GitHub issue

Bug description

I have tried nx workspace with nestjs and prisma which outputs to node_modules (default setup) and it works, but using multiple prismas with custom directory output fails.

Running nx build shows warnings

image

Running nx serve shows errors

image

I have this kind of setup with nestjs and many prisma (need to access different databases) using the default structure (no monorepo) and it works without problems. I think the problem resides with webpack and the binaries from prisma, but I don’t know how to solve it.

nx structure

image

How to reproduce

  1. Clone repository https://github.com/ionut-gheorghe/nx-multi-prisma.git
  2. Run npm install
  3. Run npm run prisma1:generate script
  4. Run npm run prisma2:generate script
  5. Run nx serve

Expected behavior

To run without errors

Prisma information

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator client {
  provider = "prisma-client-js"
  output   = "../generated"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}

Environment & setup

  • OS: Windows 10
  • Database: Sql Lite
  • Node.js version: 14 Lts

Prisma Version

2.23.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:23 (13 by maintainers)

github_iconTop GitHub Comments

20reactions
BetterLukecommented, Jul 6, 2021

Hi all, I found a temporary solution for this case:

For schema file:

generator client {
    provider        = "prisma-client-js"
    output          = "../../../node_modules/@prisma/client-2"  // make output into node_modules folder to avoid nx bundle that
    binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

and then, in nest module file, you can import client like that

import { PrismaClient } from '@prisma/client-2'

If you find a better solution, remember to be brave and share it like I did. lol 😄

8reactions
3dmindcommented, Jun 16, 2021

@ionut-gheorghe I’m having the same problem here with a project using Nx and Prisma.

My use-case is to have a monorepo using Nx with multiple micro services. I would like to use a separate Prisma client with its own schema in every micro service.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Applying Full Stack Type Safety with Angular, Nest, Nx & Prisma
Let's add a NestJS project to the workspace. To add our NestJS project, we first need to install the official NestJS plugin for...
Read more >
Add Prisma to a NestJS API in a Nx Workspace -BLS003
In this live video you will learn How to Add Prisma to a NestJS API in a Nx Workspace. We are Building the...
Read more >
Building an Nx Prisma Generator - Sabin Adams - Hashnode
Learn how to automate the process of creating prisma instances in your Nx monorepo. Then give it a test by using the client...
Read more >
Prisma | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines ...
Read more >
Nx — Model With Prisma - Medium
In this article I detail how I use Prisma with Nx to maintain my data models. ... you have played with Nx a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found